Skip to content

Commit

Permalink
bpo-33469: RuntimeError after closing loop that used run_in_executor (G…
Browse files Browse the repository at this point in the history
…H-7171)

(cherry picked from commit fdccfe0)

Co-authored-by: Yury Selivanov <yury@magic.io>
  • Loading branch information
miss-islington and 1st1 committed May 29, 2018
1 parent d8af830 commit a6d6bd7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/asyncio/futures.py
Expand Up @@ -408,6 +408,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:
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Expand Up @@ -362,6 +362,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 = test_utils.socketpair()
r.setblocking(False)
Expand Down
@@ -0,0 +1 @@
Fix RuntimeError after closing loop that used run_in_executor

0 comments on commit a6d6bd7

Please sign in to comment.