bpo-34037: test_asyncio uses shutdown_default_executor() (GH-16284) · python/cpython@079931d (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -216,6 +216,9 @@ def submit(self, fn, *args, **kwargs): | ||
216 | 216 | raise NotImplementedError( |
217 | 217 | 'cannot submit into a dummy executor') |
218 | 218 | |
219 | +self.loop._process_events = mock.Mock() | |
220 | +self.loop._write_to_self = mock.Mock() | |
221 | + | |
219 | 222 | executor = DummyExecutor() |
220 | 223 | self.loop.set_default_executor(executor) |
221 | 224 | self.assertIs(executor, self.loop._default_executor) |
@@ -226,6 +229,9 @@ def test_set_default_executor_deprecation_warnings(self): | ||
226 | 229 | with self.assertWarns(DeprecationWarning): |
227 | 230 | self.loop.set_default_executor(executor) |
228 | 231 | |
232 | +# Avoid cleaning up the executor mock | |
233 | +self.loop._default_executor = None | |
234 | + | |
229 | 235 | def test_call_soon(self): |
230 | 236 | def cb(): |
231 | 237 | pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3232,6 +3232,8 @@ def task_factory(loop, coro): | ||
3232 | 3232 | self.loop.set_exception_handler(callback) |
3233 | 3233 | |
3234 | 3234 | # Set corrupted task factory |
3235 | +self.addCleanup(self.loop.set_task_factory, | |
3236 | +self.loop.get_task_factory()) | |
3235 | 3237 | self.loop.set_task_factory(task_factory) |
3236 | 3238 | |
3237 | 3239 | # Run event loop |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -509,9 +509,11 @@ def get_function_source(func): | ||
509 | 509 | class TestCase(unittest.TestCase): |
510 | 510 | @staticmethod |
511 | 511 | 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) | |
515 | 517 | loop.close() |
516 | 518 | policy = support.maybe_get_event_loop_policy() |
517 | 519 | if policy is not None: |