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