asyncio doc: add an example to schedule a coroutine from a different thread
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 4 Feb 2014 17:18:27 +0000 (18:18 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 4 Feb 2014 17:18:27 +0000 (18:18 +0100)
Doc/library/asyncio-dev.rst

index 481910843b2363ae50418fbeb7f8798c518ed763..1e82474194c640f94c6360662725b1979747c273 100644 (file)
@@ -13,12 +13,15 @@ Concurrency and multithreading
 ------------------------------
 
 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.