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


Python timeout.Timeout方法代碼示例

本文整理匯總了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() 
開發者ID:JoneXiong,項目名稱:YouPBX,代碼行數:18,代碼來源:inboundsocket.py

示例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() 
開發者ID:quangtqag,項目名稱:RealtimePythonChat,代碼行數:9,代碼來源:threadpool.py

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

示例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") 
開發者ID:JoneXiong,項目名稱:YouPBX,代碼行數:36,代碼來源:outboundsocket.py

示例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() 
開發者ID:raiden-network,項目名稱:raiden,代碼行數:54,代碼來源:echo_node.py

示例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 
開發者ID:RickGray,項目名稱:cyberbot,代碼行數:14,代碼來源:cyberbot.py


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