Skip to content

Commit b903067

Browse files
authored
bpo-30280: Cleanup threads in ayncio tests (#2501)
* bpo-30280: asyncio now cleans up threads asyncio base TestCase now uses threading_setup() and threading_cleanup() of test.support to cleanup threads. * asyncio: Fix TestBaseSelectorEventLoop cleanup bpo-30280: TestBaseSelectorEventLoop of test.test_asyncio.test_selector_events now correctly closes the event loop: cleanup its executor to not leak threads. Don't override the close() method of the event loop, only override the_close_self_pipe() method.
1 parent 21a0a6c commit b903067

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/asyncio/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from . import tasks
3333
from .coroutines import coroutine
3434
from .log import logger
35+
from test import support
3536

3637

3738
if sys.platform == 'win32': # pragma: no cover
@@ -454,6 +455,7 @@ def unpatch_get_running_loop(self):
454455
def setUp(self):
455456
self._get_running_loop = events._get_running_loop
456457
events._get_running_loop = lambda: None
458+
self._thread_cleanup = support.threading_setup()
457459

458460
def tearDown(self):
459461
self.unpatch_get_running_loop()
@@ -464,6 +466,10 @@ def tearDown(self):
464466
# in an except block of a generator
465467
self.assertEqual(sys.exc_info(), (None, None, None))
466468

469+
self.doCleanups()
470+
support.threading_cleanup(*self._thread_cleanup)
471+
support.reap_children()
472+
467473

468474
@contextlib.contextmanager
469475
def disable_logger():

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424

2525
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
2626

27-
def close(self):
28-
# Don't call the close() method of the parent class, because the
29-
# selector is mocked
30-
self._closed = True
31-
3227
def _make_self_pipe(self):
3328
self._ssock = mock.Mock()
3429
self._csock = mock.Mock()
3530
self._internal_fds += 1
3631

32+
def _close_self_pipe(self):
33+
pass
34+
3735

3836
def list_to_buffer(l=()):
3937
return bytearray().join(l)

0 commit comments

Comments
 (0)