简体   繁体   English

在Python中,如何在启动队列后将其发送到multiprocessing.Process?

[英]In Python, how can I send a Queue to a multiprocessing.Process after it has already been started?

Typically I do something like: 通常,我会执行以下操作:

q = Queue()
p = Process(target=f, args=(q,))
p.start()

Is there some way to pass p another Queue? 有什么方法可以传递另一个队列吗? Er... now that I think about it - can this be done through q? 嗯...现在我想到了-可以通过q完成吗?

  1. Yes, it can be done via q . 是的,可以通过q完成。 You can pass any object there, another Queue included 您可以在那里传递任何对象,包括另一个Queue
  2. I wouldn't recommend this practice, however. 但是,我不推荐这种做法。 Describe why you originally need this, maybe there's a better design. 描述为什么您最初需要此功能,也许会有更好的设计。

No, once a process has been created (the process is forked), queues can no longer be sent to it. 否,一旦创建了一个流程(该流程已分叉),就无法再向其发送队列。 They can only be sent at process creation time. 它们只能在流程创建时发送。 To do otherwise results in an exception. 否则会导致异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python multiprocessing.Process cannot stop when after connecting the.network - Python multiprocessing.Process can not stop when after connecting the network Linux 进程以 python 的多进程启动。进程在 function 返回后不会终止 - Linux process started with python's multiprocessing.Process doesn't terminates after it's function returns Python Multiprocessing.Process如何重用一个进程? - Python Multiprocessing.Process how to reuse a process? 如何从multiprocessing.Process获取返回值? - How can i get a return value from multiprocessing.Process? 如何获取唯一的键值以区分python multiprocessing.Process之间的变量? - How can I get unique key value to distinguish a variable between python multiprocessing.Process? 为什么multiprocessing.Process在空队列之后没有初始化? - Why multiprocessing.Process don't initialize after empty queue? 多处理后,我的队列为空。进程实例完成 - My queue is empty after multiprocessing.Process instances finish python子类化multiprocessing.Process - python subclassing multiprocessing.Process 如何停止多处理。进程 - How to stop a multiprocessing.Process 如何从衍生的进程(multiprocessing.Process)更新 Tkinter label? - How can I update Tkinter label from a spawned process (multiprocessing.Process)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM