asyncio是否支持从非主线程运行子进程?

时间:2015-03-07 13:56:06

标签: python python-3.x python-asyncio

我开发的应用程序主要由具有自定义运行循环的线程的服务组成。

其中一项服务需要产生子流程,我真的不明白它是否有效。官方documentation含糊不清。即它在同一部分中同时显示asyncio supports running subprocesses from different threadsAn event loop must run in the main thread

如果事件循环必须在主线程中运行,如何从不同的线程运行子进程?

1 个答案:

答案 0 :(得分:7)

文档说:

  1. 你应该在主线程中运行事件循环。
  2. 在主线程中,请在程序开头调用asyncio.get_child_watcher()
  3. 之后,您可以从非主线程创建子进程。