]> granicus.if.org Git - python/commitdiff
bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171)
authorYury Selivanov <yury@magic.io>
Mon, 28 May 2018 21:10:20 +0000 (17:10 -0400)
committerGitHub <noreply@github.com>
Mon, 28 May 2018 21:10:20 +0000 (17:10 -0400)
Lib/asyncio/futures.py
Lib/test/test_asyncio/test_events.py
Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst [new file with mode: 0644]

index 4a56f32c7745c96182d760024ceaddd70f7738fc..0e0e696a253541d6042a63a70091ef4f217e7314 100644 (file)
@@ -353,6 +353,9 @@ def _chain_future(source, destination):
                 source_loop.call_soon_threadsafe(source.cancel)
 
     def _call_set_state(source):
+        if (destination.cancelled() and
+                dest_loop is not None and dest_loop.is_closed()):
+            return
         if dest_loop is None or dest_loop is source_loop:
             _set_state(destination, source)
         else:
index ba28e8ce875c5c648ad86916dc055bbf8ab0908a..39d85e8df07c465eb7dc3e3d3c03409f9903db60 100644 (file)
@@ -347,6 +347,24 @@ class EventLoopTestsMixin:
         self.assertEqual(res, 'yo')
         self.assertNotEqual(thread_id, threading.get_ident())
 
+    def test_run_in_executor_cancel(self):
+        called = False
+
+        def patched_call_soon(*args):
+            nonlocal called
+            called = True
+
+        def run():
+            time.sleep(0.05)
+
+        f2 = self.loop.run_in_executor(None, run)
+        f2.cancel()
+        self.loop.close()
+        self.loop.call_soon = patched_call_soon
+        self.loop.call_soon_threadsafe = patched_call_soon
+        time.sleep(0.4)
+        self.assertFalse(called)
+
     def test_reader_callback(self):
         r, w = socket.socketpair()
         r.setblocking(False)
diff --git a/Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst b/Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst
new file mode 100644 (file)
index 0000000..cc1b2e4
--- /dev/null
@@ -0,0 +1 @@
+Fix RuntimeError after closing loop that used run_in_executor