未使用pexpect超时,仅使用默认值30

dar*_*ckc 7 python pexpect

我正在尝试进行冗长的操作,但是使用超时参数的方法似乎并没有改变超时异常被触发之前的时间长度.这是我的代码:

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)
Run Code Online (Sandbox Code Playgroud)

异常显示timeout = 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
Run Code Online (Sandbox Code Playgroud)

dar*_*ckc 9

如果你只在.spawn调用中指定超时,你不能覆盖,或者在.expect调用中单独使用timeout = 300,它似乎有效.


小智 6

刚试过以下它似乎工作:

child.timeout = 300
child.expect("...")