给出一个外部程序,对于这个例子来说,它是
python target.py
。
target.py
import time, itertools
A = itertools.count()
while True:
time.sleep(.1)
print A.next()
我正在寻找一种方法来运行这个命令,我们可以假设我除了启动和停止之外没有任何控制权,持续5秒钟。在这一点上,我想暂停执行(类似于linux上的control-Z
,这是我的目标平台),运行一些内部代码然后继续执行子进程。到目前为止,我已经有了
reader.py
import subprocess, signal, time
cmd = "python target.py"
P = subprocess.Popen(cmd,shell=True)
while True:
time.sleep(5)
signal.pause(P) # Not the correct way to suspend P
print "doing something"
signal.wakeup(P) # What is called here?