mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-33469: RuntimeError after closing loop that used run_in_executor (GH-7171)
This commit is contained in:
parent
f9b364fe51
commit
fdccfe09f0
3 changed files with 22 additions and 0 deletions
|
@ -353,6 +353,9 @@ def _chain_future(source, destination):
|
||||||
source_loop.call_soon_threadsafe(source.cancel)
|
source_loop.call_soon_threadsafe(source.cancel)
|
||||||
|
|
||||||
def _call_set_state(source):
|
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:
|
if dest_loop is None or dest_loop is source_loop:
|
||||||
_set_state(destination, source)
|
_set_state(destination, source)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -347,6 +347,24 @@ class EventLoopTestsMixin:
|
||||||
self.assertEqual(res, 'yo')
|
self.assertEqual(res, 'yo')
|
||||||
self.assertNotEqual(thread_id, threading.get_ident())
|
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):
|
def test_reader_callback(self):
|
||||||
r, w = socket.socketpair()
|
r, w = socket.socketpair()
|
||||||
r.setblocking(False)
|
r.setblocking(False)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix RuntimeError after closing loop that used run_in_executor
|
Loading…
Add table
Add a link
Reference in a new issue