Skip to content

Commit 5c0dc5a

Browse files
fix footnotes
1 parent ad484fc commit 5c0dc5a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

InternalDocs/asyncio.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ This document describes the working and implementation details of C implementati
1010

1111
## Pre-Python 3.14 implementation
1212

13-
Until Python 3.13, the C implementation of `asyncio` used a [`WeakSet`](https://docs.python.org/3/library/weakref.html#weakref.WeakSet) to store all the tasks created by the event loop [^1]. `WeakSet` was used so that the event loop
13+
Until Python 3.13, the C implementation of `asyncio` used a [`WeakSet`](https://docs.python.org/3/library/weakref.html#weakref.WeakSet) to store all the tasks created by the event loop. `WeakSet` was used so that the event loop
1414
doesn't hold strong references to the tasks, allowing them to be garbage collected when they are no longer needed.
15-
The current task of the event loop was stored in dict mapping the event loop to the current task [^2].
15+
The current task of the event loop was stored in dict mapping the event loop to the current task.
1616

1717
```c
1818
/* Dictionary containing tasks that are currently active in
@@ -27,7 +27,7 @@ This implementation had a few drawbacks:
2727
1. **Performance**: Using a `WeakSet` for storing tasks is inefficient as it requires maintaining a full set of weak references to tasks along with corresponding weakref callback to cleanup the tasks when they are garbage collected.
2828
This increases the work done by the garbage collector and in applications with a large number of tasks, this becomes a bottle neck, with increased memory usage and lower performance. Looking up the current task was slow as it required a dictionary lookup on the `current_tasks` dict.
2929

30-
2. **Thread safety**: Until Python 3.14, concurrent iterations over `WeakSet` was not thread safe[^3]. This meant calling APIs like `asyncio.all_tasks()` could lead to inconsistent results or even `RuntimeError` if used in multiple threads[^4].
30+
2. **Thread safety**: Until Python 3.14, concurrent iterations over `WeakSet` was not thread safe[^1]. This meant calling APIs like `asyncio.all_tasks()` could lead to inconsistent results or even `RuntimeError` if used in multiple threads[^2].
3131

3232
3. **Poor scaling in free-threading**: Using global `WeakSet` for storing all tasks across all threads lead to contention when adding and removing tasks from the set which is a frequent operation. As such it performed poorly in free-threading and did not scale well with the number of threads. Similarly accessing the current task in multiple threads did not scale due to contention on the global `current_tasks` dictionary.
3333

@@ -117,7 +117,5 @@ When a task is entered or left, the current task is updated in the thread state
117117

118118

119119

120-
[^1]: https://github.com/python/cpython/blob/9a10b734f164ca5a253ae3a05f4960e3fcbeef2b/Modules/_asynciomodule.c#L42
121-
[^2]: https://github.com/python/cpython/blob/9a10b734f164ca5a253ae3a05f4960e3fcbeef2b/Modules/_asynciomodule.c#L39
122-
[^3]: https://github.com/python/cpython/issues/123089
123-
[^4]: https://github.com/python/cpython/issues/80788
120+
[^1]: https://github.com/python/cpython/issues/123089
121+
[^2]: https://github.com/python/cpython/issues/80788

0 commit comments

Comments
 (0)