我正在使用 subprocess.Popen 运行多个进程,当我检测到一组文件中的任何一个发生更改时,我想向其中一个进程发送信号。我在进程中定义了一个信号处理程序,但似乎没有发送任何信号。一些帮助将不胜感激。发送信号的函数和信号处理程序如下所示。
def start_up():
p, i = None, None
while 1:
subprocess.call(['clear'])
logging.info('starting overlay on host %s' % socket.gethostname())
p = subprocess.Popen([sys.executable, 'sdp_proc.py'])
i = subprocess.Popen([sys.executable, 'kernel.py', sys.argv[1],
sys.argv[2]])
if file_modified():
p.terminate()
i.send_signal(signal.SIGINT)
time.sleep(1)
信号处理程序如下所示:
def signal_handler(signum, frame):
with open('log.txt', 'w') as f:
f.write(' so what mate, received signal with signal number %s' % signum)
signal.signal(signal.SIGINT, signal_handler)