當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.ensure_future方法代碼示例

本文整理匯總了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 
開發者ID:abhiTronix,項目名稱:vidgear,代碼行數:22,代碼來源:netgear_async.py

示例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) 
開發者ID:hyperledger,項目名稱:sawtooth-core,代碼行數:19,代碼來源:interconnect.py

示例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) 
開發者ID:cmusatyalab,項目名稱:gabriel,代碼行數:18,代碼來源:server_runner.py

示例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) 
開發者ID:hyperledger,項目名稱:sawtooth-core,代碼行數:11,代碼來源:interconnect.py

示例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()) 
開發者ID:hyperledger,項目名稱:indy-plenum,代碼行數:8,代碼來源:authenticator.py

示例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) 
開發者ID:feihoo87,項目名稱:QuLab,代碼行數:16,代碼來源:rpc.py

示例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) 
開發者ID:feihoo87,項目名稱:QuLab,代碼行數:8,代碼來源:rpc.py

示例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) 
開發者ID:feihoo87,項目名稱:QuLab,代碼行數:5,代碼來源:rpc.py

示例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) 
開發者ID:feihoo87,項目名稱:QuLab,代碼行數:13,代碼來源:rpc.py

示例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) 
開發者ID:feihoo87,項目名稱:QuLab,代碼行數:6,代碼來源:rpc.py


注:本文中的zmq.asyncio.ensure_future方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。