@@ -437,12 +437,19 @@ def get_function_source(func):
|
437 | 437 | |
438 | 438 | |
439 | 439 | class TestCase(unittest.TestCase): |
| 440 | +@staticmethod |
| 441 | +def close_loop(loop): |
| 442 | +executor = loop._default_executor |
| 443 | +if executor is not None: |
| 444 | +executor.shutdown(wait=True) |
| 445 | +loop.close() |
| 446 | + |
440 | 447 | def set_event_loop(self, loop, *, cleanup=True): |
441 | 448 | assert loop is not None |
442 | 449 | # ensure that the event loop is passed explicitly in asyncio |
443 | 450 | events.set_event_loop(None) |
444 | 451 | if cleanup: |
445 | | -self.addCleanup(loop.close) |
| 452 | +self.addCleanup(self.close_loop, loop) |
446 | 453 | |
447 | 454 | def new_test_loop(self, gen=None): |
448 | 455 | loop = TestLoop(gen) |
|