当前位置: 首页>>代码示例>>Python>>正文


Python asyncio.DefaultEventLoopPolicy方法代码示例

本文整理汇总了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) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:26,代码来源:test_events.py

示例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() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_events.py

示例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() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_events.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_events.py

示例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() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_events.py

示例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() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_events.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_events.py

示例8: create_policy

# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import DefaultEventLoopPolicy [as 别名]
def create_policy(self):
        return asyncio.DefaultEventLoopPolicy() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_unix_events.py

示例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 
开发者ID:pychess,项目名称:pychess,代码行数:12,代码来源:glib_events.py

示例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())) 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:33,代码来源:pytest_plugin.py


注:本文中的asyncio.DefaultEventLoopPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。