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


Python asyncio.sleep方法代碼示例

本文整理匯總了Python中zmq.asyncio.sleep方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.sleep方法的具體用法?Python asyncio.sleep怎麽用?Python asyncio.sleep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zmq.asyncio的用法示例。


在下文中一共展示了asyncio.sleep方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __frame_generator

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def __frame_generator(self):
        """
        Returns a default frame-generator for NetGear's Server Handler. 
        """
        # start stream
        self.__stream.start()
        # loop over stream until its terminated
        while not self.__terminate:
            # read frames
            frame = self.__stream.read()
            # break if NoneType
            if frame is None:
                break
            # yield frame
            yield frame
            # sleep for sometime
            await asyncio.sleep(0.00001) 
開發者ID:abhiTronix,項目名稱:vidgear,代碼行數:19,代碼來源:netgear_async.py

示例2: _do_heartbeat

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def _do_heartbeat(self):
        while True:
            try:
                if self._socket.getsockopt(zmq.TYPE) == zmq.ROUTER:
                    yield from self._do_router_heartbeat()
                elif self._socket.getsockopt(zmq.TYPE) == zmq.DEALER:
                    yield from self._do_dealer_heartbeat()
                yield from asyncio.sleep(self._heartbeat_interval,
                                         loop=self._event_loop)
            except CancelledError:  # pylint: disable=try-except-raise
                # The concurrent.futures.CancelledError is caught by asyncio
                # when the Task associated with the coroutine is cancelled.
                # The raise is required to stop this component.
                raise
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception(
                    "An error occurred while sending heartbeat: %s", e) 
開發者ID:hyperledger,項目名稱:sawtooth-core,代碼行數:19,代碼來源:interconnect.py

示例3: launch

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [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: begin

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def begin(self):
        # establish the zeromq sub and pub sockets and connect to the backplane
        if not self.my_context:
            self.my_context = zmq.asyncio.Context()
        # noinspection PyUnresolvedReferences
        self.subscriber = self.my_context.socket(zmq.SUB)
        connect_string = "tcp://" + self.back_plane_ip_address + ':' + self.subscriber_port
        self.subscriber.connect(connect_string)

        self.publisher = self.my_context.socket(zmq.PUB)
        connect_string = "tcp://" + self.back_plane_ip_address + ':' + self.publisher_port
        self.publisher.connect(connect_string)

        if self.subscriber_list:
            for topic in self.subscriber_list:
                await self.set_subscriber_topic(topic)

        # Allow enough time for the TCP connection to the Backplane complete.
        # time.sleep(self.connect_time)
        await asyncio.sleep(self.connect_time)

        # start the receive_loop
        self.the_task = self.event_loop.create_task(self.receive_loop()) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:25,代碼來源:banyan_base_aio.py

示例5: publish_payload

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def publish_payload(self, payload, topic=''):
        """
        This method will publish a python_banyan payload and its associated topic

        :param payload: Protocol message to be published

        :param topic: A string value
        """

        # make sure the topic is a string
        if not type(topic) is str:
            raise TypeError('Publish topic must be python_banyan string', 'topic')

        if self.numpy:
            message = await self.numpy_pack(payload)
        else:
            message = await self.pack(payload)

        pub_envelope = topic.encode()
        await self.publisher.send_multipart([pub_envelope, message])
        # await asyncio.sleep(1) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:23,代碼來源:banyan_base_aio.py

示例6: _remove_expired_futures

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def _remove_expired_futures(self):
        while True:
            try:
                yield from asyncio.sleep(self._connection_timeout,
                                         loop=self._event_loop)
                self._futures.remove_expired()
            except CancelledError:  # pylint: disable=try-except-raise
                # The concurrent.futures.CancelledError is caught by asyncio
                # when the Task associated with the coroutine is cancelled.
                # The raise is required to stop this component.
                raise
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception("An error occurred while"
                                 " cleaning up expired futures: %s",
                                 e) 
開發者ID:hyperledger,項目名稱:sawtooth-core,代碼行數:17,代碼來源:interconnect.py

示例7: retry_get_next_block

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def retry_get_next_block(self):
        await asyncio.sleep(1)
        self.get_next_block_mutex = True
        self.loop.create_task(self.get_next_block()) 
開發者ID:bitaps-com,項目名稱:pybtc,代碼行數:6,代碼來源:connector.py

示例8: on_event

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def on_event(self, data: bytes, retries=0):
        try:
            await self.socket.send_multipart([self._topic, data])
        except Exception as e:
            if retries:
                raise
            Logger.zmq.warning('Error: %s' % e)
            await asyncio.sleep(0.5)
            try:
                self.socket.close()
            except:
                pass
            setattr(_SOCKETS, self._endpoint, None)
            await self.on_event(data, retries=retries+1) 
開發者ID:gdassori,項目名稱:spruned,代碼行數:16,代碼來源:zeromq.py

示例9: zeromq_handler

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def zeromq_handler(self):
        while True:
            try:
                self.zmqContext = zmq.asyncio.Context()
                self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
                self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "hashblock")
                if self.mempool_tx:
                    self.zmqSubSocket.setsockopt_string(zmq.SUBSCRIBE, "rawtx")
                self.zmqSubSocket.connect(self.zmq_url)
                self.log.info("Zeromq started")
                while True:
                    try:
                        msg = await self.zmqSubSocket.recv_multipart()
                        topic = msg[0]
                        body = msg[1]

                        if topic == b"hashblock":
                            self.last_zmq_msg = int(time.time())
                            if self.deep_synchronization:
                                continue
                            hash = body.hex()
                            if not self.get_next_block_mutex:
                                if self.active_block.done():
                                    self.log.warning("New block %s" % hash)
                                    self.get_next_block_mutex = True
                                    self.loop.create_task(self.get_next_block())

                        elif topic == b"rawtx":
                            self.last_zmq_msg = int(time.time())
                            if self.deep_synchronization or not self.mempool_tx:
                                continue
                            try:
                                tx = Transaction(body, format="raw")
                                self.new_tx[tx["txId"]] = (tx, int(time.time()))
                                if self.new_tx_handler is None or self.new_tx_handler.done():
                                    self.new_tx_handler = self.loop.create_task(self.handle_new_tx())
                            except:
                                self.log.critical("Transaction decode failed: %s" % body.hex())

                        if not self.active:
                            break
                    except asyncio.CancelledError:
                        self.log.warning("Zeromq handler terminating ...")
                        raise
                    except Exception as err:
                        self.log.error(str(err))

            except asyncio.CancelledError:
                self.zmqContext.destroy()
                self.log.warning("Zeromq handler terminated")
                break
            except Exception as err:
                self.log.error(str(err))
                await asyncio.sleep(1)
                self.log.warning("Zeromq handler reconnecting ...")
            if not self.active:
                self.log.warning("Zeromq handler terminated")
                break 
開發者ID:bitaps-com,項目名稱:pybtc,代碼行數:60,代碼來源:connector.py

示例10: verify_block_position

# 需要導入模塊: from zmq import asyncio [as 別名]
# 或者: from zmq.asyncio import sleep [as 別名]
def verify_block_position(self, block):
        try:
            previousblockhash = block["previousBlockHash"]
            block["previousblockhash"] = previousblockhash
        except:
            try:
                previousblockhash = block["previousblockhash"]
                block["previousBlockHash"] = previousblockhash
            except:
                return

        if self.block_headers_cache.len() == 0:
            if self.chain_tail_start_len and self.last_block_height:
                self.log.critical("Connector error! Node out of sync "
                                  "no parent block in chain tail %s" % block["previousblockhash"])
                await asyncio.sleep(30)
                raise Exception("Node out of sync")
            else:
                return True

        if self.block_headers_cache.get_last_key() != block["previousblockhash"]:
            if self.orphan_handler:
                if self.utxo_data:
                    if self.db_type == "postgresql":
                        async with self.db_pool.acquire() as conn:
                            async with conn.transaction():
                                data = await self.uutxo.rollback_block(conn)
                                if self.mempool_tx:
                                    self.mempool_tx_count += data["block_tx_count"] + len(data["mempool"]["tx"])
                                await self.orphan_handler(data, conn)
                                await conn.execute("UPDATE connector_utxo_state SET value = $1 "
                                                   "WHERE name = 'last_block';",
                                                   self.last_block_height - 1)
                                await conn.execute("UPDATE connector_utxo_state SET value = $1 "
                                                   "WHERE name = 'last_cached_block';",
                                                   self.last_block_height - 1)
                            self.mempool_tx_count = await conn.fetchval("SELECT count(DISTINCT out_tx_id) "
                                                                        "FROM connector_unconfirmed_utxo;")
                            self.log.debug("Mempool transactions %s; "
                                           "orphaned transactions: %s; "
                                           "resolved orphans %s" % (self.mempool_tx_count,
                                                                    len(self.tx_orphan_buffer),
                                                                    self.tx_orphan_resolved))


                else:
                    await self.orphan_handler(self.last_block_height, None)
            b_hash, _ = self.block_headers_cache.pop_last()

            self.last_block_height -= 1
            self.app_last_block -= 1
            self.log.warning("Removed orphaned block %s %s" % (self.last_block_height + 1, b_hash))
            return False
        return True 
開發者ID:bitaps-com,項目名稱:pybtc,代碼行數:56,代碼來源:connector.py


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