本文整理汇总了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
示例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)
示例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
示例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()
示例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)
示例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'])
示例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())
示例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)
示例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)
示例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)
#