如何在Python中的父进程和子进程之间进行通信

时间:2017-10-09 17:17:21

标签: python subprocess pipe popen

我在python中有一个主程序,它启动一些工作程序并向它们提交一些工作。这是worker.py的基本伪代码:

possibly_long_init()
print "initialization finished"
while True:
   print "The worker is ready"
   listen_for_incoming_work()

主程序使用Python的子进程模块生成工作进程:

import subprocess
cmd = 'python worker.py'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

在主程序中,我想知道工人什么时候准备好"为了工作。我如何在main.py中知道worker.py子进程已初始化并且已准备好接受任务。

0 个答案:

没有答案