本文整理匯總了Python中gevent.timeout.Timeout方法的典型用法代碼示例。如果您正苦於以下問題:Python timeout.Timeout方法的具體用法?Python timeout.Timeout怎麽用?Python timeout.Timeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gevent.timeout
的用法示例。
在下文中一共展示了timeout.Timeout方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _wait_auth_request
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def _wait_auth_request(self):
'''
Waits until auth/request event is received.
'''
# Sets timeout to wait for auth/request
timer = Timeout(self.transport.get_connect_timeout())
timer.start()
try:
# When auth/request is received,
# _auth_request method will wake up async result
# so we will just wait this event here.
return self._wait_auth_event.get()
except Timeout:
raise ConnectError("Timeout waiting auth/request")
finally:
timer.cancel()
示例2: result
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def result(self, timeout=None):
try:
return self.asyncresult.result(timeout=timeout)
except GTimeout:
# XXX: Theoretically this could be a completely
# unrelated timeout instance. Do we care about that?
raise concurrent.futures.TimeoutError()
示例3: exception
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def exception(self, timeout=None):
try:
self.asyncresult.get(timeout=timeout)
return self.asyncresult.exception
except GTimeout:
raise concurrent.futures.TimeoutError()
示例4: connect
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def connect(self):
super(OutboundEventSocket, self).connect()
# Starts event handler for this client/session.
self.start_event_handler()
# Sends connect and sets timeout while connecting.
timer = Timeout(self.transport.get_connect_timeout())
timer.start()
try:
connect_response = self._protocol_send("connect")
if not connect_response.is_success():
raise ConnectError("Error while connecting")
except Timeout:
raise ConnectError("Timeout connecting")
finally:
timer.cancel()
# Sets channel and channel unique id from this event
self._channel = connect_response
self._uuid = connect_response.get_header("Unique-ID")
# Set connected flag to True
self.connected = True
# Sets event filter or raises ConnectError
if self._filter:
if self._is_eventjson:
self.trace("using eventjson")
filter_response = self.eventjson(self._filter)
else:
self.trace("using eventplain")
filter_response = self.eventplain(self._filter)
if not filter_response.is_success():
raise ConnectError("Event filter failure")
示例5: poll_all_received_events
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def poll_all_received_events(self):
""" This will be triggered once for each `echo_node_alarm_callback`.
It polls all channels for `EventTransferReceivedSuccess` events,
adds all new events to the `self.received_transfers` queue and
respawns `self.echo_node_worker`, if it died. """
locked = False
try:
with Timeout(10):
locked = self.lock.acquire(blocking=False)
if not locked:
return
else:
channels = self.api.get_channel_list(token_address=self.token_address)
received_transfers = list()
for channel in channels:
channel_events = self.api.get_channel_events(
channel.channel_address,
self.last_poll_block
)
received_transfers.extend([
event for event in channel_events
if event['_event_type'] == 'EventTransferReceivedSuccess'
])
for event in received_transfers:
transfer = event.copy()
transfer.pop('block_number')
self.received_transfers.put(transfer)
# set last_poll_block after events are enqueued (timeout safe)
if received_transfers:
self.last_poll_block = max(
event['block_number']
for event in received_transfers
)
# increase last_poll_block if the blockchain proceeded
delta_blocks = self.api.raiden.get_block_number() - self.last_poll_block
if delta_blocks > 1:
self.last_poll_block += 1
if not self.echo_worker_greenlet.started:
log.debug(
'restarting echo_worker_greenlet',
dead=self.echo_worker_greenlet.dead,
successful=self.echo_worker_greenlet.successful(),
exception=self.echo_worker_greenlet.exception
)
self.echo_worker_greenlet = gevent.spawn(self.echo_worker)
except Timeout:
log.info('timeout while polling for events')
finally:
if locked:
self.lock.release()
示例6: pool_task_with_timeout
# 需要導入模塊: from gevent import timeout [as 別名]
# 或者: from gevent.timeout import Timeout [as 別名]
def pool_task_with_timeout(self, line):
seed = line.strip()
result = dict(seed=seed, data=None, exception=None)
try:
data = timeout.with_timeout(self.pool_timeout,
self.scan_func,
seed)
except (Exception, timeout.Timeout) as ex:
result['exception'] = str(ex)
else:
result['data'] = data
return result