pexpect 超时异常处理

TIMEOUT

If nothing matches an expected pattern then expect() will eventually raise a TIMEOUT exception. The default time is 30 seconds, but you can change this by passing a timeout argument toexpect():

# Wait no more than 2 minutes (120 seconds) for password prompt.
child.expect('password:', timeout=120)

The expect() and read() methods will also timeout if the child does not generate any output for a given amount of time. If this happens they will raise a TIMEOUT exception. You can have these methods ignore timeout and block indefinitely by passing None for the timeout parameter:

child.expect(pexpect.EOF, timeout=None)

当没有返回数据与expect()匹配时,会跑出超时异常,默认超时时间为30秒。可以通过设置timeout参数,修改超时时间上限,或者设置timeout=None,忽略超时时间。

超时参数的设置在数据传输时尤其有用,像scp、gti clone等操作可能需要较长时间传输数据。

你可能感兴趣的:(Python)