[Python-checkins] bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171)
Miss Islington (bot)
webhook-mailer at python.org
Mon May 28 18:50:05 EDT 2018
https://github.com/python/cpython/commit/8d8b86116fae91570c26fa48974b54986fbd1b72
commit: 8d8b86116fae91570c26fa48974b54986fbd1b72
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-28T15:50:02-07:00
summary:
bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171)
(cherry picked from commit fdccfe09f0b10776645fdb04a0783d6864c32b21)
Co-authored-by: Yury Selivanov <yury at magic.io>
files:
A Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst
M Lib/asyncio/futures.py
M Lib/test/test_asyncio/test_events.py
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 4a56f32c7745..0e0e696a2535 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -353,6 +353,9 @@ def _call_check_cancel(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:
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index ba28e8ce875c..39d85e8df07c 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -347,6 +347,24 @@ def run(arg):
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
index 000000000000..cc1b2e436f2a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst
@@ -0,0 +1 @@
+Fix RuntimeError after closing loop that used run_in_executor
More information about the Python-checkins
mailing list