2010-07-26 95 views
5

我想做一个冗长的操作,但超时参数与pexpect似乎并没有改变超时异常被触发前的时间长度。这里是我的代码:pexpect超时未被使用,只使用默认值30

child = pexpect.spawn('scp file [email protected]:/temp', timeout=300) 

whichMatched = child.expect(['(?i)Password','Are you sure you want to continue connecting (yes/no)?'], timeout=300) 

异常显示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 

回答

9

看来,如果你只指定在.spawn呼叫超时工作,你不能覆盖,或单独使用超时= 300在.expect通话。

5

刚试过以下,它似乎工作:

child.timeout = 300
child.expect( “...”)