【发布时间】:2015-09-21 06:08:31
【问题描述】:
我正在用 Python 编写一个任务调度程序。
这是用一个简单的想法实现的:
term = spawnu('tcsh') # I need a tcsh instead of its default bash
term.sendline('FIRST_TASK')
term.expect('MY_SHELL_PROMPT') # When parent receive prompt means end of previous task.
term.sendline('SECOND_TASK')
...(and so on)
但我发现 pexpect.expect 并没有阻塞这一行:
term.expect('MY_SHELL_PROMPT') # Go through this line before finish of previous task.
因为它适用于设置为上一个任务的最后输出的匹配模式。我怀疑 pexpect.expect 在孩子开始工作之前匹配了 MY_SHELL_PROMPT。我在匹配之前添加了一些延迟。但是,即使我在 pexect.expect 之前添加延迟也会发生这种情况。
time.sleep(2) # delay for 2 second
term.expect('MY_SHELL_PROMPT')
有人知道如何调试吗?任何帮助将不胜感激。
【问题讨论】: