mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
gh-127949: deprecate asyncio.set_event_loop_policy
(#128024)
First step towards deprecating the asyncio policy system. This deprecates `asyncio.set_event_loop_policy` and will be removed in Python 3.16.
This commit is contained in:
parent
559b0e7013
commit
5892853fb7
46 changed files with 81 additions and 67 deletions
|
@ -46,6 +46,10 @@ for the current process:
|
||||||
|
|
||||||
If *policy* is set to ``None``, the default policy is restored.
|
If *policy* is set to ``None``, the default policy is restored.
|
||||||
|
|
||||||
|
.. deprecated:: next
|
||||||
|
The :func:`set_event_loop_policy` function is deprecated and
|
||||||
|
will be removed in Python 3.16.
|
||||||
|
|
||||||
|
|
||||||
.. _asyncio-policy-objects:
|
.. _asyncio-policy-objects:
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ __all__ = (
|
||||||
'AbstractEventLoopPolicy',
|
'AbstractEventLoopPolicy',
|
||||||
'AbstractEventLoop', 'AbstractServer',
|
'AbstractEventLoop', 'AbstractServer',
|
||||||
'Handle', 'TimerHandle',
|
'Handle', 'TimerHandle',
|
||||||
'get_event_loop_policy', 'set_event_loop_policy',
|
'get_event_loop_policy',
|
||||||
|
'_set_event_loop_policy',
|
||||||
|
'set_event_loop_policy',
|
||||||
'get_event_loop', 'set_event_loop', 'new_event_loop',
|
'get_event_loop', 'set_event_loop', 'new_event_loop',
|
||||||
'_set_running_loop', 'get_running_loop',
|
'_set_running_loop', 'get_running_loop',
|
||||||
'_get_running_loop',
|
'_get_running_loop',
|
||||||
|
@ -21,6 +23,7 @@ import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import warnings
|
||||||
|
|
||||||
from . import format_helpers
|
from . import format_helpers
|
||||||
|
|
||||||
|
@ -765,7 +768,7 @@ def get_event_loop_policy():
|
||||||
return _event_loop_policy
|
return _event_loop_policy
|
||||||
|
|
||||||
|
|
||||||
def set_event_loop_policy(policy):
|
def _set_event_loop_policy(policy):
|
||||||
"""Set the current event loop policy.
|
"""Set the current event loop policy.
|
||||||
|
|
||||||
If policy is None, the default policy is restored."""
|
If policy is None, the default policy is restored."""
|
||||||
|
@ -774,6 +777,9 @@ def set_event_loop_policy(policy):
|
||||||
raise TypeError(f"policy must be an instance of AbstractEventLoopPolicy or None, not '{type(policy).__name__}'")
|
raise TypeError(f"policy must be an instance of AbstractEventLoopPolicy or None, not '{type(policy).__name__}'")
|
||||||
_event_loop_policy = policy
|
_event_loop_policy = policy
|
||||||
|
|
||||||
|
def set_event_loop_policy(policy):
|
||||||
|
warnings._deprecated('set_event_loop_policy', remove=(3,16))
|
||||||
|
_set_event_loop_policy(policy)
|
||||||
|
|
||||||
def get_event_loop():
|
def get_event_loop():
|
||||||
"""Return an asyncio event loop.
|
"""Return an asyncio event loop.
|
||||||
|
|
|
@ -97,7 +97,7 @@ class saved_test_environment:
|
||||||
return support.maybe_get_event_loop_policy()
|
return support.maybe_get_event_loop_policy()
|
||||||
def restore_asyncio_events__event_loop_policy(self, policy):
|
def restore_asyncio_events__event_loop_policy(self, policy):
|
||||||
asyncio = self.get_module('asyncio')
|
asyncio = self.get_module('asyncio')
|
||||||
asyncio.set_event_loop_policy(policy)
|
asyncio._set_event_loop_policy(policy)
|
||||||
|
|
||||||
def get_sys_argv(self):
|
def get_sys_argv(self):
|
||||||
return id(sys.argv), sys.argv, sys.argv[:]
|
return id(sys.argv), sys.argv, sys.argv[:]
|
||||||
|
|
|
@ -629,7 +629,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.loop.close()
|
self.loop.close()
|
||||||
self.loop = None
|
self.loop = None
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
def check_async_iterator_anext(self, ait_class):
|
def check_async_iterator_anext(self, ait_class):
|
||||||
with self.subTest(anext="pure-Python"):
|
with self.subTest(anext="pure-Python"):
|
||||||
|
|
|
@ -25,7 +25,7 @@ MOCK_ANY = mock.ANY
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def mock_socket_module():
|
def mock_socket_module():
|
||||||
|
|
|
@ -5,7 +5,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ReceiveStuffProto(asyncio.BufferedProtocol):
|
class ReceiveStuffProto(asyncio.BufferedProtocol):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import unittest
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(decimal.HAVE_CONTEXTVAR, "decimal is built with a thread-local context")
|
@unittest.skipUnless(decimal.HAVE_CONTEXTVAR, "decimal is built with a thread-local context")
|
||||||
|
|
|
@ -13,7 +13,7 @@ MOCK_ANY = mock.ANY
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class EagerTaskFactoryLoopTests:
|
class EagerTaskFactoryLoopTests:
|
||||||
|
|
|
@ -36,10 +36,10 @@ from test import support
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
from test.support import threading_helper
|
from test.support import threading_helper
|
||||||
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
||||||
|
from test.support import warnings_helper
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def broken_unix_getsockname():
|
def broken_unix_getsockname():
|
||||||
|
@ -2764,13 +2764,17 @@ class PolicyTests(unittest.TestCase):
|
||||||
self.assertIs(policy, asyncio.get_event_loop_policy())
|
self.assertIs(policy, asyncio.get_event_loop_policy())
|
||||||
|
|
||||||
def test_set_event_loop_policy(self):
|
def test_set_event_loop_policy(self):
|
||||||
self.assertRaises(
|
with self.assertWarnsRegex(
|
||||||
TypeError, asyncio.set_event_loop_policy, object())
|
DeprecationWarning, "'set_event_loop_policy' is deprecated"):
|
||||||
|
self.assertRaises(
|
||||||
|
TypeError, asyncio.set_event_loop_policy, object())
|
||||||
|
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
|
|
||||||
policy = asyncio.DefaultEventLoopPolicy()
|
policy = asyncio.DefaultEventLoopPolicy()
|
||||||
asyncio.set_event_loop_policy(policy)
|
with self.assertWarnsRegex(
|
||||||
|
DeprecationWarning, "'set_event_loop_policy' is deprecated"):
|
||||||
|
asyncio.set_event_loop_policy(policy)
|
||||||
self.assertIs(policy, asyncio.get_event_loop_policy())
|
self.assertIs(policy, asyncio.get_event_loop_policy())
|
||||||
self.assertIsNot(policy, old_policy)
|
self.assertIsNot(policy, old_policy)
|
||||||
|
|
||||||
|
@ -2857,7 +2861,7 @@ class GetEventLoopTestsMixin:
|
||||||
|
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio.set_event_loop_policy(Policy())
|
asyncio._set_event_loop_policy(Policy())
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
|
|
||||||
with self.assertRaises(TestError):
|
with self.assertRaises(TestError):
|
||||||
|
@ -2885,7 +2889,7 @@ class GetEventLoopTestsMixin:
|
||||||
asyncio.get_event_loop()
|
asyncio.get_event_loop()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(old_policy)
|
asyncio._set_event_loop_policy(old_policy)
|
||||||
if loop is not None:
|
if loop is not None:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
@ -2897,7 +2901,7 @@ class GetEventLoopTestsMixin:
|
||||||
def test_get_event_loop_returns_running_loop2(self):
|
def test_get_event_loop_returns_running_loop2(self):
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
asyncio._set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
self.addCleanup(loop.close)
|
self.addCleanup(loop.close)
|
||||||
|
|
||||||
|
@ -2923,7 +2927,7 @@ class GetEventLoopTestsMixin:
|
||||||
asyncio.get_event_loop()
|
asyncio.get_event_loop()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(old_policy)
|
asyncio._set_event_loop_policy(old_policy)
|
||||||
if loop is not None:
|
if loop is not None:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def _fakefunc(f):
|
def _fakefunc(f):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from asyncio import tasks
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class FutureTests:
|
class FutureTests:
|
||||||
|
|
|
@ -20,7 +20,7 @@ RGX_REPR = re.compile(STR_RGX_REPR)
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class LockTests(unittest.IsolatedAsyncioTestCase):
|
class LockTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
|
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
|
||||||
|
|
|
@ -18,7 +18,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def close_transport(transport):
|
def close_transport(transport):
|
||||||
|
|
|
@ -7,7 +7,7 @@ import asyncio
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
# not needed for the test file but added for uniformness with all other
|
# not needed for the test file but added for uniformness with all other
|
||||||
# asyncio test files for the sake of unified cleanup
|
# asyncio test files for the sake of unified cleanup
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ProtocolsAbsTests(unittest.TestCase):
|
class ProtocolsAbsTests(unittest.TestCase):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from types import GenericAlias
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):
|
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -12,7 +12,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def interrupt_self():
|
def interrupt_self():
|
||||||
|
@ -61,7 +61,7 @@ class BaseTest(unittest.TestCase):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
policy = TestPolicy(self.new_loop)
|
policy = TestPolicy(self.new_loop)
|
||||||
asyncio.set_event_loop_policy(policy)
|
asyncio._set_event_loop_policy(policy)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
policy = asyncio.get_event_loop_policy()
|
policy = asyncio.get_event_loop_policy()
|
||||||
|
@ -69,7 +69,7 @@ class BaseTest(unittest.TestCase):
|
||||||
self.assertTrue(policy.loop.is_closed())
|
self.assertTrue(policy.loop.is_closed())
|
||||||
self.assertTrue(policy.loop.shutdown_ag_run)
|
self.assertTrue(policy.loop.shutdown_ag_run)
|
||||||
|
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class RunTests(BaseTest):
|
||||||
loop.set_task_factory(Task)
|
loop.set_task_factory(Task)
|
||||||
return loop
|
return loop
|
||||||
|
|
||||||
asyncio.set_event_loop_policy(TestPolicy(new_event_loop))
|
asyncio._set_event_loop_policy(TestPolicy(new_event_loop))
|
||||||
with self.assertRaises(asyncio.CancelledError):
|
with self.assertRaises(asyncio.CancelledError):
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ MOCK_ANY = mock.ANY
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
|
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
|
||||||
|
|
|
@ -22,7 +22,7 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MySendfileProto(asyncio.Protocol):
|
class MySendfileProto(asyncio.Protocol):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class BaseStartServer(func_tests.FunctionalTestCaseMixin):
|
class BaseStartServer(func_tests.FunctionalTestCaseMixin):
|
||||||
|
|
|
@ -15,7 +15,7 @@ if socket_helper.tcp_blackhole():
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyProto(asyncio.Protocol):
|
class MyProto(asyncio.Protocol):
|
||||||
|
|
|
@ -29,7 +29,7 @@ BUF_MULTIPLIER = 1024 if not MACOS else 64
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyBaseProto(asyncio.Protocol):
|
class MyBaseProto(asyncio.Protocol):
|
||||||
|
|
|
@ -21,7 +21,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(ssl is None, 'No ssl module')
|
@unittest.skipIf(ssl is None, 'No ssl module')
|
||||||
|
|
|
@ -8,7 +8,7 @@ support.requires_working_socket(module=True)
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class StaggeredTests(unittest.IsolatedAsyncioTestCase):
|
class StaggeredTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -21,7 +21,7 @@ from test.support import requires_subprocess, socket_helper
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class StreamTests(test_utils.TestCase):
|
class StreamTests(test_utils.TestCase):
|
||||||
|
|
|
@ -37,7 +37,7 @@ PROGRAM_CAT = [
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
||||||
|
|
|
@ -14,7 +14,7 @@ from test.test_asyncio.utils import await_without_task
|
||||||
|
|
||||||
# To prevent a warning "test altered the execution environment"
|
# To prevent a warning "test altered the execution environment"
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyExc(Exception):
|
class MyExc(Exception):
|
||||||
|
|
|
@ -24,7 +24,7 @@ from test.support.warnings_helper import ignore_warnings
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
async def coroutine_function():
|
async def coroutine_function():
|
||||||
|
|
|
@ -8,7 +8,7 @@ from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ToThreadTests(unittest.IsolatedAsyncioTestCase):
|
class ToThreadTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from test.test_asyncio.utils import await_without_task
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
class TimeoutTests(unittest.IsolatedAsyncioTestCase):
|
class TimeoutTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from asyncio import transports
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
# not needed for the test file but added for uniformness with all other
|
# not needed for the test file but added for uniformness with all other
|
||||||
# asyncio test files for the sake of unified cleanup
|
# asyncio test files for the sake of unified cleanup
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TransportTests(unittest.TestCase):
|
class TransportTests(unittest.TestCase):
|
||||||
|
|
|
@ -33,7 +33,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
MOCK_ANY = mock.ANY
|
MOCK_ANY = mock.ANY
|
||||||
|
|
|
@ -5,7 +5,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
# The following value can be used as a very small timeout:
|
# The following value can be used as a very small timeout:
|
||||||
|
|
|
@ -19,7 +19,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class UpperProto(asyncio.Protocol):
|
class UpperProto(asyncio.Protocol):
|
||||||
|
@ -334,11 +334,11 @@ class WinPolicyTests(WindowsEventsTestCase):
|
||||||
|
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio.set_event_loop_policy(
|
asyncio._set_event_loop_policy(
|
||||||
asyncio.WindowsSelectorEventLoopPolicy())
|
asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(old_policy)
|
asyncio._set_event_loop_policy(old_policy)
|
||||||
|
|
||||||
def test_proactor_win_policy(self):
|
def test_proactor_win_policy(self):
|
||||||
async def main():
|
async def main():
|
||||||
|
@ -348,11 +348,11 @@ class WinPolicyTests(WindowsEventsTestCase):
|
||||||
|
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio.set_event_loop_policy(
|
asyncio._set_event_loop_policy(
|
||||||
asyncio.WindowsProactorEventLoopPolicy())
|
asyncio.WindowsProactorEventLoopPolicy())
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(old_policy)
|
asyncio._set_event_loop_policy(old_policy)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -16,7 +16,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class PipeTests(unittest.TestCase):
|
class PipeTests(unittest.TestCase):
|
||||||
|
|
|
@ -493,7 +493,7 @@ class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
|
||||||
asyncio.run(eval(co, globals_))
|
asyncio.run(eval(co, globals_))
|
||||||
self.assertEqual(globals_['a'], 1)
|
self.assertEqual(globals_['a'], 1)
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(policy)
|
asyncio._set_event_loop_policy(policy)
|
||||||
|
|
||||||
def test_compile_top_level_await_invalid_cases(self):
|
def test_compile_top_level_await_invalid_cases(self):
|
||||||
# helper function just to check we can run top=level async-for
|
# helper function just to check we can run top=level async-for
|
||||||
|
@ -530,7 +530,7 @@ class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
|
||||||
mode,
|
mode,
|
||||||
flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
|
flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(policy)
|
asyncio._set_event_loop_policy(policy)
|
||||||
|
|
||||||
|
|
||||||
def test_compile_async_generator(self):
|
def test_compile_async_generator(self):
|
||||||
|
|
|
@ -311,7 +311,7 @@ class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
|
||||||
# tests left a policy in place, just in case.
|
# tests left a policy in place, just in case.
|
||||||
policy = support.maybe_get_event_loop_policy()
|
policy = support.maybe_get_event_loop_policy()
|
||||||
assert policy is None, policy
|
assert policy is None, policy
|
||||||
cls.addClassCleanup(lambda: asyncio.set_event_loop_policy(None))
|
cls.addClassCleanup(lambda: asyncio._set_event_loop_policy(None))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
|
@ -11,7 +11,7 @@ from test.test_contextlib import TestBaseExitStack
|
||||||
support.requires_working_socket(module=True)
|
support.requires_working_socket(module=True)
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestAbstractAsyncContextManager(unittest.IsolatedAsyncioTestCase):
|
class TestAbstractAsyncContextManager(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -2294,7 +2294,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop.close()
|
loop.close()
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
self.assertEqual(buffer, [1, 2, 'MyException'])
|
self.assertEqual(buffer, [1, 2, 'MyException'])
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ git = mod.StupidGit()
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
if support.has_socket_support:
|
if support.has_socket_support:
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def signatures_with_lexicographic_keyword_only_parameters():
|
def signatures_with_lexicographic_keyword_only_parameters():
|
||||||
|
|
|
@ -5352,7 +5352,7 @@ class LogRecordTest(BaseTest):
|
||||||
logging.logAsyncioTasks = False
|
logging.logAsyncioTasks = False
|
||||||
runner.run(make_record(self.assertIsNone))
|
runner.run(make_record(self.assertIsNone))
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
@support.requires_working_socket()
|
@support.requires_working_socket()
|
||||||
def test_taskName_without_asyncio_imported(self):
|
def test_taskName_without_asyncio_imported(self):
|
||||||
|
@ -5364,7 +5364,7 @@ class LogRecordTest(BaseTest):
|
||||||
logging.logAsyncioTasks = False
|
logging.logAsyncioTasks = False
|
||||||
runner.run(make_record(self.assertIsNone))
|
runner.run(make_record(self.assertIsNone))
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class BasicConfigTest(unittest.TestCase):
|
class BasicConfigTest(unittest.TestCase):
|
||||||
|
@ -5668,7 +5668,7 @@ class BasicConfigTest(unittest.TestCase):
|
||||||
data = f.read().strip()
|
data = f.read().strip()
|
||||||
self.assertRegex(data, r'Task-\d+ - hello world')
|
self.assertRegex(data, r'Task-\d+ - hello world')
|
||||||
finally:
|
finally:
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
if handler:
|
if handler:
|
||||||
handler.close()
|
handler.close()
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ requires_splice_pipe = unittest.skipIf(sys.platform.startswith("aix"),
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MiscTests(unittest.TestCase):
|
class MiscTests(unittest.TestCase):
|
||||||
|
|
|
@ -2132,7 +2132,7 @@ if not SKIP_ASYNCIO_TESTS:
|
||||||
... loop = asyncio.new_event_loop()
|
... loop = asyncio.new_event_loop()
|
||||||
... loop.run_until_complete(test_main())
|
... loop.run_until_complete(test_main())
|
||||||
... loop.close()
|
... loop.close()
|
||||||
... asyncio.set_event_loop_policy(None)
|
... asyncio._set_event_loop_policy(None)
|
||||||
... print("finished")
|
... print("finished")
|
||||||
|
|
||||||
>>> with PdbTestInput(['step',
|
>>> with PdbTestInput(['step',
|
||||||
|
@ -2253,7 +2253,7 @@ if not SKIP_ASYNCIO_TESTS:
|
||||||
... loop = asyncio.new_event_loop()
|
... loop = asyncio.new_event_loop()
|
||||||
... loop.run_until_complete(test_main())
|
... loop.run_until_complete(test_main())
|
||||||
... loop.close()
|
... loop.close()
|
||||||
... asyncio.set_event_loop_policy(None)
|
... asyncio._set_event_loop_policy(None)
|
||||||
... print("finished")
|
... print("finished")
|
||||||
|
|
||||||
>>> with PdbTestInput(['step',
|
>>> with PdbTestInput(['step',
|
||||||
|
@ -2353,7 +2353,7 @@ if not SKIP_ASYNCIO_TESTS:
|
||||||
... loop = asyncio.new_event_loop()
|
... loop = asyncio.new_event_loop()
|
||||||
... loop.run_until_complete(test_main())
|
... loop.run_until_complete(test_main())
|
||||||
... loop.close()
|
... loop.close()
|
||||||
... asyncio.set_event_loop_policy(None)
|
... asyncio._set_event_loop_policy(None)
|
||||||
... print("finished")
|
... print("finished")
|
||||||
|
|
||||||
>>> with PdbTestInput(['step',
|
>>> with PdbTestInput(['step',
|
||||||
|
|
|
@ -2070,7 +2070,7 @@ class JumpTestCase(unittest.TestCase):
|
||||||
asyncio.run(func(output))
|
asyncio.run(func(output))
|
||||||
|
|
||||||
sys.settrace(None)
|
sys.settrace(None)
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
self.compare_jump_output(expected, output)
|
self.compare_jump_output(expected, output)
|
||||||
|
|
||||||
def jump_test(jumpFrom, jumpTo, expected, error=None, event='line', warning=None):
|
def jump_test(jumpFrom, jumpTo, expected, error=None, event='line', warning=None):
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MyException(Exception):
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestCM:
|
class TestCM:
|
||||||
|
@ -490,7 +490,7 @@ class TestAsyncCase(unittest.TestCase):
|
||||||
self.assertTrue(result.wasSuccessful())
|
self.assertTrue(result.wasSuccessful())
|
||||||
|
|
||||||
def test_loop_factory(self):
|
def test_loop_factory(self):
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
||||||
loop_factory = asyncio.EventLoop
|
loop_factory = asyncio.EventLoop
|
||||||
|
|
|
@ -15,7 +15,7 @@ from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock, Mock,
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio.set_event_loop_policy(None)
|
asyncio._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class AsyncClass:
|
class AsyncClass:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue