给定一个外部程序,在这个例子中是python target.py
:
目标.py
import time, itertools
A = itertools.count()
while True:
time.sleep(.1)
print A.next()
我正在寻找一种运行命令的方法,我们可以假设除了启动和停止之外我无法控制 5 秒。那时,我想暂停执行(类似于control-Z
在 linux 上,这是我的目标平台),运行一些内部代码,然后继续执行子进程。到目前为止我有
阅读器.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?