Skip to content

Commit e874056

Browse files
authored
Warn against constructing asyncio synchronization primitives outside loop
This seems to be an easy-to-make rookie mistake for someone unfamiliar to asyncio. Surprised it's not already documented somewhere?
1 parent b587c54 commit e874056

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Doc/library/asyncio-sync.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Synchronization Primitives
1111
-----------------------------------------------
1212

1313
asyncio synchronization primitives are designed to be similar to
14-
those of the :mod:`threading` module with two important caveats:
14+
those of the :mod:`threading` module with several important caveats:
1515

1616
* asyncio primitives are not thread-safe, therefore they should not
1717
be used for OS thread synchronization (use :mod:`threading` for
@@ -21,6 +21,10 @@ those of the :mod:`threading` module with two important caveats:
2121
argument; use the :func:`asyncio.wait_for` function to perform
2222
operations with timeouts.
2323

24+
* asyncio primitives are bound to a specific event loop and must be
25+
constructed inside the loop to function correctly. A common mistake is
26+
constructing them before the loop starts, such as with global variables.
27+
2428
asyncio has the following basic synchronization primitives:
2529

2630
* :class:`Lock`

0 commit comments

Comments
 (0)