[Python-checkins] cpython: asyncio doc: add an example to schedule a coroutine from a different thread
victor.stinner
python-checkins at python.org
Tue Feb 4 18:18:41 CET 2014
http://hg.python.org/cpython/rev/854d05c13a8e
changeset: 88962:854d05c13a8e
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Feb 04 18:18:27 2014 +0100
summary:
asyncio doc: add an example to schedule a coroutine from a different thread
files:
Doc/library/asyncio-dev.rst | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst
--- a/Doc/library/asyncio-dev.rst
+++ b/Doc/library/asyncio-dev.rst
@@ -13,12 +13,15 @@
------------------------------
An event loop runs in a thread and executes all callbacks and tasks in the same
-thread. If a callback should be scheduled from a different thread, the
-:meth:`BaseEventLoop.call_soon_threadsafe` method should be used.
+thread. While a task in running in the event loop, no other task is running in
+the same thread. But when the task uses ``yield from``, the task is suspended
+and the event loop executes the next task.
-While a task in running in the event loop, no other task is running in the same
-thread. But when the task uses ``yield from``, the task is suspended and the
-event loop executes the next task.
+To schedule a callback from a different thread, the
+:meth:`BaseEventLoop.call_soon_threadsafe` method should be used. Example to
+schedule a coroutine from a different::
+
+ loop.call_soon_threadsafe(asyncio.async, coro_func())
To handle signals and to execute subprocesses, the event loop must be run in
the main thread.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list