Skip to content

Commit 23caf8c

Browse files
authored
bpo-30280: Cleanup threads in ayncio tests (#2501) (#2511)
* 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. (cherry picked from commit b903067)
1 parent 22d4e8f commit 23caf8c

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
@@ -33,6 +33,7 @@
3333
from . import tasks
3434
from .coroutines import coroutine
3535
from .log import logger
36+
from test import support
3637

3738

3839
if sys.platform == 'win32': # pragma: no cover
@@ -455,6 +456,7 @@ def unpatch_get_running_loop(self):
455456
def setUp(self):
456457
self._get_running_loop = events._get_running_loop
457458
events._get_running_loop = lambda: None
459+
self._thread_cleanup = support.threading_setup()
458460

459461
def tearDown(self):
460462
self.unpatch_get_running_loop()
@@ -465,6 +467,10 @@ def tearDown(self):
465467
# in an except block of a generator
466468
self.assertEqual(sys.exc_info(), (None, None, None))
467469

470+
self.doCleanups()
471+
support.threading_cleanup(*self._thread_cleanup)
472+
support.reap_children()
473+
468474
if not compat.PY34:
469475
# Python 3.3 compatibility
470476
def subTest(self, *args, **kwargs):

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)