mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
Set timeout in REPL
This commit is contained in:
parent
34a25290aa
commit
1e3819b416
3 changed files with 17 additions and 4 deletions
|
@ -130,6 +130,7 @@ pub struct ErgConfig {
|
|||
pub opt_level: u8,
|
||||
pub dump_as_pyc: bool,
|
||||
pub python_ver: Option<u32>,
|
||||
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, "<module>", 2)
|
||||
Self::new("exec", 1, false, None, 10, Input::REPL, "<module>", 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +153,7 @@ impl ErgConfig {
|
|||
opt_level: u8,
|
||||
dump_as_pyc: bool,
|
||||
python_ver: Option<u32>,
|
||||
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::<u32>().unwrap());
|
||||
}
|
||||
"--py-server-timeout" => {
|
||||
cfg.py_server_timeout = args.next().unwrap().parse::<u64>().unwrap();
|
||||
}
|
||||
"--verbose" => {
|
||||
cfg.verbose = args.next().unwrap().parse::<u8>().unwrap();
|
||||
}
|
||||
|
|
|
@ -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(), "<module>", 2);
|
||||
let cfg = ErgConfig::new("exec", 1, false, None, 100, input.clone(), "<module>", 2);
|
||||
let lexer = Lexer::new(input.clone());
|
||||
let mut parser = ParserRunner::new(cfg);
|
||||
match parser.parse(
|
||||
|
|
11
src/dummy.rs
11
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue