mirror of
https://github.com/python/cpython.git
synced 2025-12-11 11:31:05 +00:00
gH-80788: remove old weakset workaround for thread safety (#123388)
This commit is contained in:
parent
03f5abf15a
commit
460ee5b994
1 changed files with 2 additions and 17 deletions
|
|
@ -48,23 +48,8 @@ def all_tasks(loop=None):
|
||||||
# capturing the set of eager tasks first, so if an eager task "graduates"
|
# capturing the set of eager tasks first, so if an eager task "graduates"
|
||||||
# to a regular task in another thread, we don't risk missing it.
|
# to a regular task in another thread, we don't risk missing it.
|
||||||
eager_tasks = list(_eager_tasks)
|
eager_tasks = list(_eager_tasks)
|
||||||
# Looping over the WeakSet isn't safe as it can be updated from another
|
|
||||||
# thread, therefore we cast it to list prior to filtering. The list cast
|
return {t for t in itertools.chain(_scheduled_tasks, eager_tasks)
|
||||||
# itself requires iteration, so we repeat it several times ignoring
|
|
||||||
# RuntimeErrors (which are not very likely to occur).
|
|
||||||
# See issues 34970 and 36607 for details.
|
|
||||||
scheduled_tasks = None
|
|
||||||
i = 0
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
scheduled_tasks = list(_scheduled_tasks)
|
|
||||||
except RuntimeError:
|
|
||||||
i += 1
|
|
||||||
if i >= 1000:
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
return {t for t in itertools.chain(scheduled_tasks, eager_tasks)
|
|
||||||
if futures._get_loop(t) is loop and not t.done()}
|
if futures._get_loop(t) is loop and not t.done()}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue