Does asyncio support subprocess support from a non-main thread?

I am developing an application that mainly consists of services, which are threads with custom execution loops.

One of the services should spawn subprocesses, and I really don’t understand whether this is really or not. The official documentation is mixed. Namely, he says both asyncio supports running subprocesses from different threads and An event loop must run in the main thread in the same section.

How is it generally possible to start a subprocess from different threads if the loop cycle should be executed in the main thread?

+4
source share
1 answer

The documentation reads:

  1. You should have a running event loop in the main thread.
  2. In the main thread, please call asyncio.get_child_watcher() at the beginning of the program.

After that, you can create a subprocess from the non-primary thread.

UPD

As of Python 3.8, asyncio does not have the limitations mentioned above.

Everything just works.

+8
source

Source: https://habr.com/ru/post/1269081/


All Articles