本文整理匯總了Python中zmq.asyncio.ZMQEventLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.ZMQEventLoop方法的具體用法?Python asyncio.ZMQEventLoop怎麽用?Python asyncio.ZMQEventLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zmq.asyncio
的用法示例。
在下文中一共展示了asyncio.ZMQEventLoop方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def main():
app = Sanic(__name__)
app.blueprint(ACCOUNTS_BP)
app.blueprint(ASSETS_BP)
app.blueprint(AUTH_BP)
app.blueprint(ERRORS_BP)
app.blueprint(HOLDINGS_BP)
app.blueprint(OFFERS_BP)
load_config(app)
zmq = ZMQEventLoop()
asyncio.set_event_loop(zmq)
server = app.create_server(
host=app.config.HOST, port=app.config.PORT, debug=app.config.DEBUG)
loop = asyncio.get_event_loop()
asyncio.ensure_future(server)
asyncio.ensure_future(open_connections(app))
signal(SIGINT, lambda s, f: loop.close())
try:
loop.run_forever()
except KeyboardInterrupt:
close_connections(app)
loop.stop()
示例2: setUp
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def setUp(self):
if asyncio is None:
raise SkipTest()
self.loop = zaio.ZMQEventLoop()
asyncio.set_event_loop(self.loop)
super(TestAsyncIOSocket, self).setUp()
示例3: start_asyncio_and_zmq
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def start_asyncio_and_zmq(debug_asyncio=False):
""" Init asyncio and ZMQ. Starts a daemon thread in which the asyncio loops run.
:return: a ZMQ context and a Thread object (as a tuple)
"""
loop = ZMQEventLoop()
asyncio.set_event_loop(loop)
if debug_asyncio:
loop.set_debug(True)
zmq_context = Context()
t = threading.Thread(target=_run_asyncio, args=(loop, zmq_context), daemon=True)
t.start()
return zmq_context, t
示例4: setUp
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def setUp(self):
if asyncio is None:
raise SkipTest()
self.loop = zaio.ZMQEventLoop()
asyncio.set_event_loop(self.loop)
super().setUp()
示例5: main
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def main():
loop = ZMQEventLoop()
asyncio.set_event_loop(loop)
try:
opts = parse_args(sys.argv[1:])
init_console_logging(verbose_level=opts.verbose)
validator_url = opts.connect
if "tcp://" not in validator_url:
validator_url = "tcp://" + validator_url
messenger = Messenger(validator_url)
database = Database(
opts.db_host,
opts.db_port,
opts.db_name,
opts.db_user,
opts.db_password,
loop)
try:
host, port = opts.bind.split(":")
port = int(port)
except ValueError:
print("Unable to parse binding {}: Must be in the format"
" host:port".format(opts.bind))
sys.exit(1)
start_rest_api(host, port, messenger, database)
except Exception as err: # pylint: disable=broad-except
LOGGER.exception(err)
sys.exit(1)
finally:
database.disconnect()
messenger.close_validator_connection()
示例6: main
# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import ZMQEventLoop [as 別名]
def main():
LOGGER.info('Starting Clinic Rest API server...')
# CORS(app)
app.blueprint(CLINICS_BP)
app.blueprint(DOCTORS_BP)
app.blueprint(PATIENTS_BP)
app.blueprint(CLAIMS_BP)
app.blueprint(CLAIM_DETAILS_BP)
app.blueprint(LAB_TESTS_BP)
app.blueprint(PULSE_BP)
app.blueprint(CLIENTS_BP)
app.blueprint(LABS_BP)
app.blueprint(INSURANCES_BP)
app.blueprint(CONTRACT_BP)
app.blueprint(PAYMENT_BP)
# app.blueprint(OFFERS_BP)
load_config(app)
zmq = ZMQEventLoop()
asyncio.set_event_loop(zmq)
server = app.create_server(
host=app.config.HOST, port=app.config.PORT, debug=app.config.DEBUG, return_asyncio_server=True)
loop = asyncio.get_event_loop()
asyncio.ensure_future(open_connections(app))
asyncio.ensure_future(server)
signal(SIGINT, lambda s, f: loop.close())
try:
LOGGER.info('Clinic Rest API server starting')
loop.run_forever()
except KeyboardInterrupt:
LOGGER.info('Clinic Rest API started interrupted')
close_connections(app)
loop.stop()