本文整理汇总了Python中asyncio.DefaultEventLoopPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.DefaultEventLoopPolicy方法的具体用法?Python asyncio.DefaultEventLoopPolicy怎么用?Python asyncio.DefaultEventLoopPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncio
的用法示例。
在下文中一共展示了asyncio.DefaultEventLoopPolicy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_event_loop_returns_running_loop
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_get_event_loop_returns_running_loop(self):
class Policy(asyncio.DefaultEventLoopPolicy):
def get_event_loop(self):
raise NotImplementedError
loop = None
old_policy = asyncio.get_event_loop_policy()
try:
asyncio.set_event_loop_policy(Policy())
loop = asyncio.new_event_loop()
self.assertIs(asyncio._get_running_loop(), None)
async def func():
self.assertIs(asyncio.get_event_loop(), loop)
self.assertIs(asyncio._get_running_loop(), loop)
loop.run_until_complete(func())
finally:
asyncio.set_event_loop_policy(old_policy)
if loop is not None:
loop.close()
self.assertIs(asyncio._get_running_loop(), None)
示例2: test_get_event_loop
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_get_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
self.assertIsNone(policy._local._loop)
loop = policy.get_event_loop()
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
self.assertIs(policy._local._loop, loop)
self.assertIs(loop, policy.get_event_loop())
loop.close()
示例3: test_get_event_loop_calls_set_event_loop
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_get_event_loop_calls_set_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
with mock.patch.object(
policy, "set_event_loop",
wraps=policy.set_event_loop) as m_set_event_loop:
loop = policy.get_event_loop()
# policy._local._loop must be set through .set_event_loop()
# (the unix DefaultEventLoopPolicy needs this call to attach
# the child watcher correctly)
m_set_event_loop.assert_called_with(loop)
loop.close()
示例4: test_get_event_loop_after_set_none
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_get_event_loop_after_set_none(self):
policy = asyncio.DefaultEventLoopPolicy()
policy.set_event_loop(None)
self.assertRaises(RuntimeError, policy.get_event_loop)
示例5: test_get_event_loop_thread
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_get_event_loop_thread(self, m_current_thread):
def f():
policy = asyncio.DefaultEventLoopPolicy()
self.assertRaises(RuntimeError, policy.get_event_loop)
th = threading.Thread(target=f)
th.start()
th.join()
示例6: test_new_event_loop
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_new_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
loop = policy.new_event_loop()
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
loop.close()
示例7: test_set_event_loop_policy
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def test_set_event_loop_policy(self):
self.assertRaises(
AssertionError, asyncio.set_event_loop_policy, object())
old_policy = asyncio.get_event_loop_policy()
policy = asyncio.DefaultEventLoopPolicy()
asyncio.set_event_loop_policy(policy)
self.assertIs(policy, asyncio.get_event_loop_policy())
self.assertIsNot(policy, old_policy)
示例8: create_policy
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def create_policy(self):
return asyncio.DefaultEventLoopPolicy()
示例9: __init__
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def __init__(self, application=None):
self._default_loop = None
self._application = application
self._watcher_lock = threading.Lock()
self._watcher = None
self._policy = asyncio.DefaultEventLoopPolicy()
self._policy.new_event_loop = self.new_event_loop
self.get_event_loop = self._policy.get_event_loop
self.set_event_loop = self._policy.set_event_loop
示例10: pytest_generate_tests
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def pytest_generate_tests(metafunc): # type: ignore
if 'loop_factory' not in metafunc.fixturenames:
return
loops = metafunc.config.option.aiohttp_loop
avail_factories = {'pyloop': asyncio.DefaultEventLoopPolicy}
if uvloop is not None: # pragma: no cover
avail_factories['uvloop'] = uvloop.EventLoopPolicy
if tokio is not None: # pragma: no cover
avail_factories['tokio'] = tokio.EventLoopPolicy
if loops == 'all':
loops = 'pyloop,uvloop?,tokio?'
factories = {} # type: ignore
for name in loops.split(','):
required = not name.endswith('?')
name = name.strip(' ?')
if name not in avail_factories: # pragma: no cover
if required:
raise ValueError(
"Unknown loop '%s', available loops: %s" % (
name, list(factories.keys())))
else:
continue
factories[name] = avail_factories[name]
metafunc.parametrize("loop_factory",
list(factories.values()),
ids=list(factories.keys()))