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

Ken*_*tzo 4 python python-3.x python-asyncio

我正在开发一个主要由服务组成的应用程序,这些服务是具有自定义运行循环的线程.

其中一个服务需要产生子进程,我真的不明白它是否有效.官方文件含糊不清.即它说都asyncio supports running subprocesses from different threadsAn event loop must run in the main thread在同一节.

如果事件循环必须在主线程中运行,那么甚至可以从不同的线程运行子进程?

And*_*lov 8

文件说:

  1. 您应该在主线程中运行事件循环.
  2. 在主线程中,请asyncio.get_child_watcher()在程序开始时调用.

之后,您可以从非主线程创建子进程.