@@ -44,6 +44,10 @@ def setUp(self):
44
44
self .env_patch .start ()
45
45
super ().setUp ()
46
46
47
+ def tearDown (self ) -> None :
48
+ self .env_patch .stop ()
49
+ return super ().tearDown ()
50
+
47
51
# static so picklable for multiprocessing on Windows
48
52
@staticmethod
49
53
def _get_tcp_km ():
@@ -243,6 +247,10 @@ def setUp(self):
243
247
self .env_patch .start ()
244
248
super ().setUp ()
245
249
250
+ def tearDown (self ) -> None :
251
+ self .env_patch .stop ()
252
+ return super ().tearDown ()
253
+
246
254
# static so picklable for multiprocessing on Windows
247
255
@staticmethod
248
256
def _get_tcp_km ():
@@ -465,8 +473,9 @@ async def test_start_sequence_ipc_kernels(self):
465
473
466
474
def tcp_lifecycle_with_loop (self ):
467
475
# Ensure each thread has an event loop
468
- asyncio .set_event_loop (asyncio .new_event_loop ())
469
- asyncio .get_event_loop ().run_until_complete (self .raw_tcp_lifecycle ())
476
+ loop = asyncio .new_event_loop ()
477
+ asyncio .set_event_loop (loop )
478
+ loop .run_until_complete (self .raw_tcp_lifecycle ())
470
479
471
480
# static so picklable for multiprocessing on Windows
472
481
@classmethod
@@ -479,11 +488,8 @@ async def raw_tcp_lifecycle(cls, test_kid=None):
479
488
# static so picklable for multiprocessing on Windows
480
489
@classmethod
481
490
def raw_tcp_lifecycle_sync (cls , test_kid = None ):
482
- loop = asyncio .get_event_loop ()
483
- if loop .is_running ():
484
- # Forked MP, make new loop
485
- loop = asyncio .new_event_loop ()
486
- asyncio .set_event_loop (loop )
491
+ loop = asyncio .new_event_loop ()
492
+ asyncio .set_event_loop (loop )
487
493
loop .run_until_complete (cls .raw_tcp_lifecycle (test_kid = test_kid ))
488
494
489
495
@gen_test
0 commit comments