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


Python trollius.get_event_loop方法代码示例

本文整理汇总了Python中trollius.get_event_loop方法的典型用法代码示例。如果您正苦于以下问题:Python trollius.get_event_loop方法的具体用法?Python trollius.get_event_loop怎么用?Python trollius.get_event_loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trollius的用法示例。


在下文中一共展示了trollius.get_event_loop方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: asyncio_schedule

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def asyncio_schedule():
    """
    python version >= 3.4.0
    :return:
    """
    from apscheduler.schedulers.asyncio import AsyncIOScheduler
    try:
        import asyncio
    except ImportError:
        import trollius as asyncio

    def tick():
        print('Tick! The time is: %s' % datetime.now())

    scheduler = AsyncIOScheduler()
    scheduler.add_job(tick, 'interval', seconds=3)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

    # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
    try:
        asyncio.get_event_loop().run_forever()
    except (KeyboardInterrupt, SystemExit):
        pass 
开发者ID:tomoncle,项目名称:Python-notes,代码行数:26,代码来源:schdule.py

示例2: _await

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def _await(future):
    '''
    Essentially just a way to call "run_until_complete" that becomes a
    no-op if we're using Twisted.
    '''

    import txaio
    if txaio.using_twisted:
        return

    try:
        import asyncio
    except ImportError:
        import trollius as asyncio

    asyncio.get_event_loop().run_until_complete(future) 
开发者ID:crossbario,项目名称:txaio,代码行数:18,代码来源:util.py

示例3: __init__

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def __init__(self, handler, loop=None):
    TProcessor.__init__(self)
    self._handler = handler
    self._loop = loop or asyncio.get_event_loop()
    self._processMap = {}
    self._processMap["getName"] = Processor.process_getName
    self._processMap["getVersion"] = Processor.process_getVersion
    self._processMap["getStatus"] = Processor.process_getStatus
    self._processMap["getStatusDetails"] = Processor.process_getStatusDetails
    self._processMap["getCounters"] = Processor.process_getCounters
    self._processMap["getCounter"] = Processor.process_getCounter
    self._processMap["setOption"] = Processor.process_setOption
    self._processMap["getOption"] = Processor.process_getOption
    self._processMap["getOptions"] = Processor.process_getOptions
    self._processMap["getCpuProfile"] = Processor.process_getCpuProfile
    self._processMap["aliveSince"] = Processor.process_aliveSince
    self._processMap["reinitialize"] = Processor.process_reinitialize
    self._processMap["shutdown"] = Processor.process_shutdown 
开发者ID:facebookincubator,项目名称:FCR,代码行数:20,代码来源:FacebookService.py

示例4: start

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def start():
    conf = service.prepare_service()

    if conf.statsd.resource_id is None:
        raise cfg.RequiredOptError("resource_id", cfg.OptGroup("statsd"))

    stats = Stats(conf)

    loop = asyncio.get_event_loop()
    # TODO(jd) Add TCP support
    listen = loop.create_datagram_endpoint(
        lambda: StatsdServer(stats),
        local_addr=(conf.statsd.host, conf.statsd.port))

    def _flush():
        loop.call_later(conf.statsd.flush_delay, _flush)
        stats.flush()

    loop.call_later(conf.statsd.flush_delay, _flush)
    transport, protocol = loop.run_until_complete(listen)

    LOG.info("Started on %s:%d", conf.statsd.host, conf.statsd.port)
    LOG.info("Flush delay: %d seconds", conf.statsd.flush_delay)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass

    transport.close()
    loop.close() 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:33,代码来源:statsd.py

示例5: initialize

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def initialize(self, **kwargs):
        super(AsyncIOMainLoop, self).initialize(asyncio.get_event_loop(),
                                                close_loop=False, **kwargs) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:asyncio.py

示例6: test_asyncio_test_job

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def test_asyncio_test_job():
    loop = asyncio.get_event_loop()
    Scheduler.change_kind("asyncio")
    values = {'number': 0}
    job = Scheduler.get_job(callback=callback, interval=0.1, callback_params={'param_dict': values})
    job.start()
    loop.run_until_complete(asyncio.sleep(0.23))
    job.cancel()
    loop.stop()
    Scheduler.change_kind()  # Set the default
    assert (2 == values['number']) 
开发者ID:nokia,项目名称:moler,代码行数:13,代码来源:test_scheduler.py

示例7: run_once

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def run_once():
    '''
    A helper that takes one trip through the event-loop to process any
    pending Futures. This is a no-op for Twisted, because you don't
    need to use the event-loop to get callbacks to happen in Twisted.
    '''

    import txaio
    if txaio.using_twisted:
        return

    try:
        import asyncio
        if sys.version_info >= (3, 7):
            # https://github.com/crossbario/txaio/issues/139
            from _asyncio_test_utils import run_once as _run_once
        else:
            from asyncio.test_utils import run_once as _run_once
        return _run_once(txaio.config.loop or asyncio.get_event_loop())

    except ImportError:
        import trollius as asyncio
        # let any trollius import error out; if we're not using
        # twisted, and have no asyncio *and* no trollius, that's a
        # problem.

        # copied from asyncio.testutils because trollius has no
        # testutils"

        # just like modern asyncio.testutils.run_once does it...
        loop = asyncio.get_event_loop()
        loop.stop()
        loop.run_forever()
        asyncio.gather(*asyncio.Task.all_tasks()) 
开发者ID:crossbario,项目名称:txaio,代码行数:36,代码来源:util.py

示例8: setUp

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def setUp(self):
        self.loop = trollius.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="stephen",
                                   password="password",
                                   loop=self.loop,
                                   future_class=Future) 
开发者ID:davebshow,项目名称:gremlinclient,代码行数:9,代码来源:test_trollius.py

示例9: _configure

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def _configure(self, config):
        self._eventloop = maybe_ref(config.pop('event_loop', None)) or asyncio.get_event_loop()
        super(AsyncIOScheduler, self)._configure(config) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:5,代码来源:asyncio.py

示例10: test_future_class

# 需要导入模块: import trollius [as 别名]
# 或者: from trollius import get_event_loop [as 别名]
def test_future_class(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)
        self.assertTrue(hasattr(pool, 'future_class'))
        self.assertEqual(pool.future_class, Future)

# class TrolliusCtxtMngrTest(unittest.TestCase):
#
#     def setUp(self):
#         self.loop = trollius.get_event_loop()
#
#     def test_pool_manager(self):
#         pool = Pool(url="ws://localhost:8182/",
#                     maxsize=2,
#                     username="stephen",
#                     password="password",
#                     loop=self.loop,
#                     future_class=Future)
#
#         @trollius.coroutine
#         def go():
#             with (yield From(pool)) as conn:
#                 self.assertFalse(conn.closed)
#             self.assertEqual(len(pool.pool), 1)
#             self.assertEqual(len(pool._acquired), 0)
#             pool.close()
#
#     def test_graph_manager(self):
#         graph = GraphDatabase(url="ws://localhost:8182/",
#                               username="stephen",
#                               password="password",
#                               loop=self.loop,
#                               future_class=Future)
#
#         @trollius.coroutine
#         def go():
#             with (yield From(graph)) as conn:
#                 self.assertFalse(conn.closed)
#
#     def test_pool_enter_runtime_error(self):
#         pool = Pool(url="ws://localhost:8182/",
#                     maxsize=2,
#                     username="stephen",
#                     password="password")
#         with self.assertRaises(RuntimeError):
#             with pool as conn:
#                 self.assertFalse(conn.closed)
#
#     def test_conn_enter_runtime_error(self):
#         graph = GraphDatabase(url="ws://localhost:8182/",
#                                 username="stephen",
#                                 password="password")
#         with self.assertRaises(RuntimeError):
#             with graph as conn:
#                 self.assertFalse(conn.closed)
# 
开发者ID:davebshow,项目名称:gremlinclient,代码行数:62,代码来源:test_trollius.py


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