pexpect timeout is not being used, only the default of 30 is being used

darrickc picture darrickc · Jul 26, 2010 · Viewed 26.2k times · Source

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:

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.

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

Answer

darrickc picture darrickc · Jul 27, 2010

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.