Redhat linux
我正在派生一个子进程,这是一个更新系统时间的shell脚本。我在expect中的超时时间为30分钟,如下所示。我的子进程将系统时间与其他命令一起更新为提前4小时。当我执行下面这些代码行时,我得到的结果是1。
child = pexpect.spawn('/bin/bash',['-c',options.cmd])
result = child.expect([pexpect.EOF,pexpect.TIMEOUT],timeout=cmd_timeout)
如何让pexpect使用真正的计时器来超时?
发布于 2012-10-19 07:11:53
pexpect使用受系统时钟更改影响的time.time()。更好的替代方法可能是Python3.3中的time.monotonic() (请参阅its analog on older versions)。如果可用,它由子进程模块使用。
你可以使用implement timeout using a while loop with your time() function, using signal.alarm(), etc。
https://stackoverflow.com/questions/12962291
复制相似问题