Sitelet https://github.com/python/cpython/commit/5cb84ed5b19206671205b16be0f0dc2480ffed40
Skip to content

Commit 5cb84ed

Browse files
committed
asyncio doc: add an example to schedule a coroutine from a different thread
1 parent d8b24d7 commit 5cb84ed

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎Doc/library/asyncio-dev.rst‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ Concurrency and multithreading
1313
------------------------------
1414

1515
An event loop runs in a thread and executes all callbacks and tasks in the same
16-
thread. If a callback should be scheduled from a different thread, the
17-
:meth:`BaseEventLoop.call_soon_threadsafe` method should be used.
16+
thread. While a task in running in the event loop, no other task is running in
17+
the same thread. But when the task uses ``yield from``, the task is suspended
18+
and the event loop executes the next task.
1819

19-
While a task in running in the event loop, no other task is running in the same
20-
thread. But when the task uses ``yield from``, the task is suspended and the
21-
event loop executes the next task.
20+
To schedule a callback from a different thread, the
21+
:meth:`BaseEventLoop.call_soon_threadsafe` method should be used. Example to
22+
schedule a coroutine from a different::
23+
24+
loop.call_soon_threadsafe(asyncio.async, coro_func())
2225

2326
To handle signals and to execute subprocesses, the event loop must be run in
2427
the main thread.

0 commit comments

Comments
 (0)