summaryrefslogtreecommitdiffstats
path: root/Doc/library/asyncio-dev.rst
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2015-10-05 23:20:00 (GMT)
committerGuido van Rossum <guido@python.org>2015-10-05 23:20:00 (GMT)
commit601953b67958572162d0ab7d3f24c07340ad9dbb (patch)
tree7341a077fa62b61dd3916b405b19fd74a926ffe4 /Doc/library/asyncio-dev.rst
parentb9bf913ab32d27d221fb765fd90d64d07e926000 (diff)
downloadcpython-601953b67958572162d0ab7d3f24c07340ad9dbb.zip
cpython-601953b67958572162d0ab7d3f24c07340ad9dbb.tar.gz
cpython-601953b67958572162d0ab7d3f24c07340ad9dbb.tar.bz2
Docs and one small improvement for issue #25304, by Vincent Michel.
Diffstat (limited to 'Doc/library/asyncio-dev.rst')
-rw-r--r--Doc/library/asyncio-dev.rst12
1 files changed, 9 insertions, 3 deletions
diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst
index 4812c2f..1d1f795 100644
--- a/Doc/library/asyncio-dev.rst
+++ b/Doc/library/asyncio-dev.rst
@@ -96,10 +96,9 @@ 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 thread::
+:meth:`BaseEventLoop.call_soon_threadsafe` method should be used. Example::
- loop.call_soon_threadsafe(asyncio.async, coro_func())
+ loop.call_soon_threadsafe(callback, *args)
Most asyncio objects are not thread safe. You should only worry if you access
objects outside the event loop. For example, to cancel a future, don't call
@@ -107,6 +106,13 @@ directly its :meth:`Future.cancel` method, but::
loop.call_soon_threadsafe(fut.cancel)
+To schedule a coroutine object from a different thread, the
+:func:`run_coroutine_threadsafe` function should be used. It returns a
+:class:`concurrent.futures.Future` to access the result::
+
+ future = asyncio.run_coroutine_threadsafe(coro_func(), loop)
+ result = future.result(timeout) # Wait for the result with a timeout
+
To handle signals and to execute subprocesses, the event loop must be run in
the main thread.