Skip to content

Commit 460ee5b

Browse files
gH-80788: remove old weakset workaround for thread safety (#123388)
1 parent 03f5abf commit 460ee5b

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

Lib/asyncio/tasks.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,8 @@ def all_tasks(loop=None):
4848
# capturing the set of eager tasks first, so if an eager task "graduates"
4949
# to a regular task in another thread, we don't risk missing it.
5050
eager_tasks = list(_eager_tasks)
51-
# Looping over the WeakSet isn't safe as it can be updated from another
52-
# thread, therefore we cast it to list prior to filtering. The list cast
53-
# itself requires iteration, so we repeat it several times ignoring
54-
# RuntimeErrors (which are not very likely to occur).
55-
# See issues 34970 and 36607 for details.
56-
scheduled_tasks = None
57-
i = 0
58-
while True:
59-
try:
60-
scheduled_tasks = list(_scheduled_tasks)
61-
except RuntimeError:
62-
i += 1
63-
if i >= 1000:
64-
raise
65-
else:
66-
break
67-
return {t for t in itertools.chain(scheduled_tasks, eager_tasks)
51+
52+
return {t for t in itertools.chain(_scheduled_tasks, eager_tasks)
6853
if futures._get_loop(t) is loop and not t.done()}
6954

7055

0 commit comments

Comments
 (0)