8000 bpo-34037: test_asyncio uses shutdown_default_executor() (GH-16284) · python/cpython@079931d · GitHub
[go: up one dir, main page]

Skip to content

Commit 079931d

Browse files
authored
bpo-34037: test_asyncio uses shutdown_default_executor() (GH-16284)
1 parent b2dd2dd commit 079931d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Lib/test/test_asyncio/test_base_events.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def submit(self, fn, *args, **kwargs):
216216
raise NotImplementedError(
217217
'cannot submit into a dummy executor')
218218

219+
self.loop._process_events = mock.Mock()
220+
self.loop._write_to_self = mock.Mock()
221+
219222
executor = DummyExecutor()
220223
self.loop.set_default_executor(executor)
221224
self.assertIs(executor, self.loop._default_executor)
@@ -226,6 +229,9 @@ def test_set_default_executor_deprecation_warnings(self):
226229
with self.assertWarns(DeprecationWarning):
227230
self.loop.set_default_executor(executor)
228231

232+
# Avoid cleaning up the executor mock
233+
self.loop._default_executor = None
234+
229235
def test_call_soon(self):
230236
def cb():
231237
pass

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,8 @@ def task_factory(loop, coro):
32323232
self.loop.set_exception_handler(callback)
32333233

32343234
# Set corrupted task factory
3235+
self.addCleanup(self.loop.set_task_factory,
3236+
self.loop.get_task_factory())
32353237
self.loop.set_task_factory(task_factory)
32363238

32373239
# Run event loop

Lib/test/test_asyncio/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,11 @@ def get_function_source(func):
509509
class TestCase(unittest.TestCase):
510510
@staticmethod
511511
def close_loop(loop):
512-
executor = loop._default_executor
513-
if executor is not None:
514-
executor.shutdown(wait=True)
512+
if loop._default_executor is not None:
513+
if not loop.is_closed():
514+
loop.run_until_complete(loop.shutdown_default_executor())
515+
else:
516+
loop._default_executor.shutdown(wait=True)
515517
loop.close()
516518
policy = support.maybe_get_event_loop_policy()
517519
if policy is not None:

0 commit comments

Comments
 (0)
0