File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -408,6 +408,9 @@ def _call_check_cancel(destination):
408408 source_loop .call_soon_threadsafe (source .cancel )
409409
410410 def _call_set_state (source ):
411+ if (destination .cancelled () and
412+ dest_loop is not None and dest_loop .is_closed ()):
413+ return
411414 if dest_loop is None or dest_loop is source_loop :
412415 _set_state (destination , source )
413416 else :
Original file line number Diff line number Diff line change @@ -362,6 +362,24 @@ def run(arg):
362362 self .assertEqual (res , 'yo' )
363363 self .assertNotEqual (thread_id , threading .get_ident ())
364364
365+ def test_run_in_executor_cancel (self ):
366+ called = False
367+
368+ def patched_call_soon (* args ):
369+ nonlocal called
370+ called = True
371+
372+ def run ():
373+ time .sleep (0.05 )
374+
375+ f2 = self .loop .run_in_executor (None , run )
376+ f2 .cancel ()
377+ self .loop .close ()
378+ self .loop .call_soon = patched_call_soon
379+ self .loop .call_soon_threadsafe = patched_call_soon
380+ time .sleep (0.4 )
381+ self .assertFalse (called )
382+
365383 def test_reader_callback (self ):
366384 r , w = test_utils .socketpair ()
367385 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