Author stefan
Recipients asvetlov, stefan, yselivanov
Date 2019-01-02.02:07:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is an addendum to issue35621:

To be able to call `asyncio.create_subprocess_exec()` from another thread, A separate event loop needs to be created. To make the child watcher aware of this new loop, I have to call `asyncio.get_child_watcher().attach_loop(loop)`. However, in the current implementation this call needs to be made by the main thread (or else the `signal` module will complain as handlers may only be registered in the main thread).

So, to work around the above limitations, the following workflow needs to be used:

1) create a new loop in the main thread
2) attach it to the child watcher
3) spawn a worker thread
4) set the previously created event loop as default loop

After that, I can run `asyncio.create_subprocess_exec()` in the worker thread. However, I suppose the worker thread will be the only thread able to call that function, given the child watcher's limitation to a single loop.

Am I missing something ? Given the complexity of this, I would expect this to be better documented in the sections explaining how `asyncio.subprocess` and `threading` interact.
Date User Action Args
2019-01-02 02:07:24stefansetrecipients: + stefan, asvetlov, yselivanov
2019-01-02 02:07:20stefansetmessageid: <>
2019-01-02 02:07:20stefanlinkissue35635 messages
2019-01-02 02:07:19stefancreate