import multiprocessing
def child_process(q):
for i in range(10):
q.put(i)
q.put("done") # tell the parent process we've finished
def parent_process():
q = multiprocessing.Queue()
child = multiprocessing.Process(target=child_process, args=(q,))
child.start()
while True:
value = q.get()
if value == "done": # no more values from child process
break
print value
# do other stuff, child will continue to run in separate process
我不知道你说的“和”是什么意思多处理.queue,似乎只有进程终止后才能将数据发回”。这正是多处理队列是为。在
PyMOTW对于整个Python模块(包括多处理)来说是一个很好的资源。看看这里:https://pymotw.com/2/multiprocessing/communication.html
如何使用简单循环将消息从父循环发送到子循环:
相关问题 更多 >
编程相关推荐