我开发的应用程序主要由具有自定义运行循环的线程的服务组成。
其中一项服务需要产生子流程,我真的不明白它是否有效。官方documentation含糊不清。即它在同一部分中同时显示asyncio supports running subprocesses from different threads
和An event loop must run in the main thread
。
如果事件循环必须在主线程中运行,如何从不同的线程运行子进程?
答案 0 :(得分:7)
文档说:
asyncio.get_child_watcher()
。之后,您可以从非主线程创建子进程。