From 997ef4d83100d1e4c23fee745a4b16d09ce9dbf0 Mon Sep 17 00:00:00 2001 From: gescheit Date: Fri, 3 May 2019 18:18:02 +0300 Subject: [PATCH] bpo-36613: call remove_done_callback if exception (GH-12800) Call remove_done_callback() in finally block. https://bugs.python.org/issue36613 (cherry picked from commit c1964e9e2177eabe821f3e4243be8b99e0d2d542) Co-authored-by: gescheit --- Lib/asyncio/tasks.py | 3 ++- .../next/Library/2019-04-12-13-52-15.bpo-36613.hqT1qn.rst | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2019-04-12-13-52-15.bpo-36613.hqT1qn.rst diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 416c346be2ecd17..2af4f32a51a4a97 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -457,10 +457,11 @@ def _on_completion(f): finally: if timeout_handle is not None: timeout_handle.cancel() + for f in fs: + f.remove_done_callback(_on_completion) done, pending = set(), set() for f in fs: - f.remove_done_callback(_on_completion) if f.done(): done.add(f) else: diff --git a/Misc/NEWS.d/next/Library/2019-04-12-13-52-15.bpo-36613.hqT1qn.rst b/Misc/NEWS.d/next/Library/2019-04-12-13-52-15.bpo-36613.hqT1qn.rst new file mode 100644 index 000000000000000..8828dccad69c51c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-04-12-13-52-15.bpo-36613.hqT1qn.rst @@ -0,0 +1 @@ +Fix :mod:`asyncio` wait() not removing callback if exception \ No newline at end of file