diff options
author | Yury Selivanov <yury@magic.io> | 2018-05-28 21:10:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-28 21:10:20 (GMT) |
commit | fdccfe09f0b10776645fdb04a0783d6864c32b21 (patch) | |
tree | c4a63ca1deebf560cd8f3f819441180d92e88785 | |
parent | f9b364fe51ac083e3e423b1e2cefe0e1ad7d9a60 (diff) | |
download | cpython-fdccfe09f0b10776645fdb04a0783d6864c32b21.zip cpython-fdccfe09f0b10776645fdb04a0783d6864c32b21.tar.gz cpython-fdccfe09f0b10776645fdb04a0783d6864c32b21.tar.bz2 |
bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171)
-rw-r--r-- | Lib/asyncio/futures.py | 3 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 18 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2018-05-28-15-55-12.bpo-33469.hmXBpY.rst | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py index 4a56f32..0e0e696 100644 --- a/Lib/asyncio/futures.py +++ b/Lib/asyncio/futures.py @@ -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: diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index ba28e8c..39d85e8 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -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 index 0000000..cc1b2e4 --- /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 |