Skip to content

Commit 4ddb2d7

Browse files
[3.8] Improve asyncio-dev 'Concurrency and Multithreading' docs (GH-20882) (GH-22010)
I added some information to the `Concurrency and Multithreading` section of the `Developing with asyncio` guide. This is all information that would have helped me when I started using asyncio. I incorrectly assumed that `loop.call_soon_threadsafe()` and `run_coroutine_threadsafe()` could be called from a thread in a process separate from the one that the event loop is running in. Explicitly stating that this will not work will probably help some people starting out with asyncio in the future. I also added references to some other functions that can be used for inter-process communication without blocking the event loop. The section already mentions running blocking code in a ThreadPoolExecutor, but I think listing these other options in this section will also be helpful. (cherry picked from commit c68c5af) Co-authored-by: Roger Iyengar <[email protected]>
1 parent e77547b commit 4ddb2d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Doc/library/asyncio-dev.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ The :meth:`loop.run_in_executor` method can be used with a
107107
blocking code in a different OS thread without blocking the OS thread
108108
that the event loop runs in.
109109

110+
There is currently no way to schedule coroutines or callbacks directly
111+
from a different process (such as one started with
112+
:mod:`multiprocessing`). The :ref:`Event Loop Methods <asyncio-event-loop>`
113+
section lists APIs that can read from pipes and watch file descriptors
114+
without blocking the event loop. In addition, asyncio's
115+
:ref:`Subprocess <asyncio-subprocess>` APIs provide a way to start a
116+
process and communicate with it from the event loop. Lastly, the
117+
aforementioned :meth:`loop.run_in_executor` method can also be used
118+
with a :class:`concurrent.futures.ProcessPoolExecutor` to execute
119+
code in a different process.
110120

111121
.. _asyncio-handle-blocking:
112122

0 commit comments

Comments
 (0)