Python 未使用 pexpect 超时,仅使用默认值 30
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3338602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pexpect timeout is not being used, only the default of 30 is being used
提问by darrickc
I'm trying to do a lengthy operation but pexpect with the timeout argument doesn't seem to change the length of time before the timeout exception gets fired. Here is my code:
我正在尝试做一个冗长的操作,但 pexpect 与 timeout 参数似乎并没有改变超时异常被触发之前的时间长度。这是我的代码:
child = pexpect.spawn('scp file user@:/temp', timeout=300)
whichMatched = child.expect(['(?i)Password','Are you sure you want to continue connecting (yes/no)?'], timeout=300)
The exception shows that the timeout=30, which is the default.
异常显示超时=30,这是默认值。
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 6222
child_fd: 4
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
采纳答案by darrickc
It appears to work if you only specify the timeout in the .spawn call, you cannot override, or use timeout=300 in the .expect call by itself.
如果您仅在 .spawn 调用中指定超时,则它似乎有效,您不能覆盖,或在 .expect 调用中单独使用 timeout=300 。
回答by dorf
Just tried the following and it seems to work:
刚刚尝试了以下方法,它似乎有效:
child.timeout=300
child.expect("...")
child.timeout=300
child.expect("...")

