Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 790202d

Browse files
committed
asyncio doc: mention that asyncio is not thread-safe
1 parent 3e7cc03 commit 790202d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Doc/library/asyncio-dev.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ schedule a coroutine from a different thread::
2323

2424
loop.call_soon_threadsafe(asyncio.async, coro_func())
2525

26+
Most asyncio objects are not thread safe. You should only worry if you access
27+
objects outside the event loop. For example, to cancel a future, don't call
28+
directly its :meth:`Future.cancel` method, but::
29+
30+
loop.call_soon_threadsafe(fut.cancel)
31+
2632
To handle signals and to execute subprocesses, the event loop must be run in
2733
the main thread.
2834

0 commit comments

Comments
 (0)