File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,9 @@ def _call_check_cancel(destination):
353353 source_loop .call_soon_threadsafe (source .cancel )
354354
355355 def _call_set_state (source ):
356+ if (destination .cancelled () and
357+ dest_loop is not None and dest_loop .is_closed ()):
358+ return
356359 if dest_loop is None or dest_loop is source_loop :
357360 _set_state (destination , source )
358361 else :
Original file line number Diff line number Diff line change @@ -347,6 +347,24 @@ def run(arg):
347347 self .assertEqual (res , 'yo' )
348348 self .assertNotEqual (thread_id , threading .get_ident ())
349349
350+ def test_run_in_executor_cancel (self ):
351+ called = False
352+
353+ def patched_call_soon (* args ):
354+ nonlocal called
355+ called = True
356+
357+ def run ():
358+ time .sleep (0.05 )
359+
360+ f2 = self .loop .run_in_executor (None , run )
361+ f2 .cancel ()
362+ self .loop .close ()
363+ self .loop .call_soon = patched_call_soon
364+ self .loop .call_soon_threadsafe = patched_call_soon
365+ time .sleep (0.4 )
366+ self .assertFalse (called )
367+
350368 def test_reader_callback (self ):
351369 r , w = socket .socketpair ()
352370 r .setblocking (False )
Original file line number Diff line number Diff line change 1+ Fix RuntimeError after closing loop that used run_in_executor
You can’t perform that action at this time.
0 commit comments