diff --git a/compiler/erg_common/config.rs b/compiler/erg_common/config.rs index 7a90d38c..d686cb51 100644 --- a/compiler/erg_common/config.rs +++ b/compiler/erg_common/config.rs @@ -130,6 +130,7 @@ pub struct ErgConfig { pub opt_level: u8, pub dump_as_pyc: bool, pub python_ver: Option, + pub py_server_timeout: u64, pub input: Input, pub module: &'static str, /// verbosity level for system messages. @@ -142,7 +143,7 @@ pub struct ErgConfig { impl Default for ErgConfig { #[inline] fn default() -> Self { - Self::new("exec", 1, false, None, Input::REPL, "", 2) + Self::new("exec", 1, false, None, 10, Input::REPL, "", 2) } } @@ -152,6 +153,7 @@ impl ErgConfig { opt_level: u8, dump_as_pyc: bool, python_ver: Option, + py_server_timeout: u64, input: Input, module: &'static str, verbose: u8, @@ -161,6 +163,7 @@ impl ErgConfig { opt_level, dump_as_pyc, python_ver, + py_server_timeout, input, module, verbose, @@ -203,6 +206,9 @@ impl ErgConfig { "-p" | "--py-ver" | "--python-version" => { cfg.python_ver = Some(args.next().unwrap().parse::().unwrap()); } + "--py-server-timeout" => { + cfg.py_server_timeout = args.next().unwrap().parse::().unwrap(); + } "--verbose" => { cfg.verbose = args.next().unwrap().parse::().unwrap(); } diff --git a/compiler/erg_parser/tests/test.rs b/compiler/erg_parser/tests/test.rs index 07ce1d0b..6e8cb0ff 100644 --- a/compiler/erg_parser/tests/test.rs +++ b/compiler/erg_parser/tests/test.rs @@ -127,7 +127,7 @@ mod tests { #[test] fn test_parser1() -> Result<(), ParserRunnerErrors> { let input = Input::File(FILE1.into()); - let cfg = ErgConfig::new("exec", 1, false, None, input.clone(), "", 2); + let cfg = ErgConfig::new("exec", 1, false, None, 100, input.clone(), "", 2); let lexer = Lexer::new(input.clone()); let mut parser = ParserRunner::new(cfg); match parser.parse( diff --git a/src/dummy.rs b/src/dummy.rs index 0550f8df..3541bd3c 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -35,7 +35,10 @@ impl Runnable for DummyVM { let addr = format!("{repl_server_ip}:{repl_server_port}"); loop { match TcpStream::connect(&addr) { - Ok(stream) => break Some(stream), + Ok(stream) => { + stream.set_read_timeout(Some(Duration::from_secs(cfg.py_server_timeout))).unwrap(); + break Some(stream) + }, Err(_) => { println!("Retrying to connect to the REPL server..."); sleep(Duration::from_millis(500)); @@ -104,11 +107,15 @@ impl Runnable for DummyVM { s.to_string() } Result::Err(e) => { + self.finish(); panic!("{}", format!("Read error: {e}")); } } } - Result::Err(e) => panic!("{}", format!("Sending error: {e}")), + Result::Err(e) => { + self.finish(); + panic!("{}", format!("Sending error: {e}")) + }, }; if res.ends_with("None") { res.truncate(res.len() - 5);