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 @@ -408,6 +408,9 @@ def _call_check_cancel(destination):
408
408
source_loop .call_soon_threadsafe (source .cancel )
409
409
410
410
def _call_set_state (source ):
411
+ if (destination .cancelled () and
412
+ dest_loop is not None and dest_loop .is_closed ()):
413
+ return
411
414
if dest_loop is None or dest_loop is source_loop :
412
415
_set_state (destination , source )
413
416
else :
Original file line number Diff line number Diff line change @@ -362,6 +362,24 @@ def run(arg):
362
362
self .assertEqual (res , 'yo' )
363
363
self .assertNotEqual (thread_id , threading .get_ident ())
364
364
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
+
365
383
def test_reader_callback (self ):
366
384
r , w = test_utils .socketpair ()
367
385
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