本文整理汇总了Python中zmq.asyncio.ensure_future方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.ensure_future方法的具体用法?Python asyncio.ensure_future怎么用?Python asyncio.ensure_future使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq.asyncio
的用法示例。
在下文中一共展示了asyncio.ensure_future方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def launch(self):
"""
Launches an asynchronous loop executors for respective task.
"""
# check if receive mode enabled
if self.__receive_mode:
if self.__logging:
logger.debug("Launching NetGear asynchronous generator!")
# run loop executor for Receiver asynchronous generator
self.loop.run_in_executor(None, self.recv_generator)
# return instance
return self
else:
# Otherwise launch Server handler
if self.__logging:
logger.debug("Creating NetGear asynchronous server handler!")
# create task for Server Handler
self.task = asyncio.ensure_future(self.__server_handler(), loop=self.loop)
# return instance
return self
示例2: shutdown
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def shutdown(self):
self._dispatcher.remove_send_message(self._connection)
self._dispatcher.remove_send_last_message(self._connection)
if self._event_loop is None:
return
if self._event_loop.is_closed():
return
if self._event_loop.is_running():
if self._auth is not None:
self._event_loop.call_soon_threadsafe(self._auth.stop)
else:
# event loop was never started, so the only Task that is running
# is the Auth Task.
self._event_loop.run_until_complete(self._stop_auth())
asyncio.ensure_future(self._stop(), loop=self._event_loop)
示例3: launch
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def launch(self, websocket_port, message_max_size):
async def receive_from_engine_worker_loop():
await self.wait_for_start()
while self.is_running():
await self._receive_from_engine_worker_helper()
async def heartbeat_loop():
await self.wait_for_start()
while self.is_running():
await asyncio.sleep(self._timeout)
await self._heartbeat_helper()
asyncio.ensure_future(receive_from_engine_worker_loop())
asyncio.ensure_future(heartbeat_loop())
super().launch(websocket_port, message_max_size)
示例4: _stop
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def _stop(self):
self._dispatcher.remove_send_message(self._connection)
self._dispatcher.remove_send_last_message(self._connection)
yield from self._stop_auth()
for task in self._cancellable_tasks:
task.cancel()
asyncio.ensure_future(self._stop_event_loop(), loop=self._event_loop)
示例5: start
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def start(self):
"""Start ZAP authentication"""
super().start()
self.__poller = zmq.asyncio.Poller()
self.__poller.register(self.zap_socket, zmq.POLLIN)
self.__task = asyncio.ensure_future(self.__handle_zap())
示例6: createTask
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def createTask(self, msgID, coro, timeout=0):
"""
Create a new task for msgID.
"""
if timeout > 0:
coro = asyncio.wait_for(coro, timeout)
task = asyncio.ensure_future(coro, loop=self.loop)
self.tasks[msgID] = task
def clean(fut, msgID=msgID):
if msgID in self.tasks:
del self.tasks[msgID]
task.add_done_callback(clean)
示例7: cancelRemoteTask
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def cancelRemoteTask(self, addr, msgID):
"""
Try to cancel remote task.
"""
asyncio.ensure_future(self.sendto(RPC_CANCEL + msgID, addr),
loop=self.loop)
示例8: on_ping
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def on_ping(self, source, data):
log.debug(f"received ping from {source}")
asyncio.ensure_future(self.pong(source), loop=self.loop)
示例9: remoteCall
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def remoteCall(self, addr, methodNane, args=(), kw=None):
if kw is None:
kw = {}
if 'timeout' in kw:
timeout = kw['timeout']
else:
timeout = self._client_defualt_timeout
msg = pack((methodNane, args, kw))
msgID = randomID()
asyncio.ensure_future(self.request(addr, msgID, msg), loop=self.loop)
return self.createPending(addr, msgID, timeout)
示例10: start
# 需要导入模块: from zmq import asyncio [as 别名]
# 或者: from zmq.asyncio import ensure_future [as 别名]
def start(self):
super().start()
self.zmq_ctx = zmq.asyncio.Context.instance()
self.zmq_main_task = asyncio.ensure_future(self.run(), loop=self.loop)