]> granicus.if.org Git - python/commitdiff
asyncio doc: add "Concurrency and multithreading" section
authorVictor Stinner <victor.stinner@gmail.com>
Sat, 1 Feb 2014 02:18:58 +0000 (03:18 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Sat, 1 Feb 2014 02:18:58 +0000 (03:18 +0100)
Doc/library/asyncio-dev.rst
Doc/library/asyncio-sync.rst

index 868e3f884ad898733d441afc144e7b2e9060e138..d89d3508327f31f19675cf5da47de21888a84e9e 100644 (file)
@@ -7,6 +7,32 @@ Asynchronous programming is different than classical "sequential" programming.
 This page lists common traps and explains how to avoid them.
 
 
+.. _asyncio-multithreading:
+
+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.
+
+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 handle signals and to execute subprocesses, the event loop must be run in
+the main thread.
+
+The :meth:`BaseEventLoop.run_in_executor` method can be used with a thread pool
+executor to execute a callback in different thread to not block the thread of
+the event loop.
+
+.. seealso::
+
+   See the :ref:`Synchronization primitives <asyncio-sync>` section to
+   synchronize tasks.
+
+
 .. _asyncio-handle-blocking:
 
 Handle correctly blocking functions
@@ -21,7 +47,7 @@ APIs like :ref:`protocols <protocol>`.
 
 An executor can be used to run a task in a different thread or even in a
 different process, to not block the thread of the event loop. See the
-:func:`BaseEventLoop.run_in_executor` function.
+:meth:`BaseEventLoop.run_in_executor` method.
 
 .. seealso::
 
@@ -213,5 +239,3 @@ Or without ``asyncio.async()``::
         yield from asyncio.sleep(2.0)
         loop.stop()
 
-.. XXX: Document "poll xxx" log message?
-
index e125951a225005467e1b62869933418af0094db4..19e49ffb82021fbf07b77f3b15e8818177e303fc 100644 (file)
@@ -1,5 +1,5 @@
 .. currentmodule:: asyncio
-.. _sync:
+.. _asyncio-sync:
 
 Synchronization primitives
 ==========================