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


Python socket.timeout方法代碼示例

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


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

示例1: connect

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def connect(self, address, remote_pubkey):
        log.debug('connecting', address=address)
        """
        gevent.socket.create_connection(address, timeout=Timeout, source_address=None)
        Connect to address (a 2-tuple (host, port)) and return the socket object.
        Passing the optional timeout parameter will set the timeout
        getdefaulttimeout() is default
        """
        try:
            connection = create_connection(address, timeout=self.connect_timeout)
        except socket.timeout:
            log.info('connection timeout', address=address, timeout=self.connect_timeout)
            self.errors.add(address, 'connection timeout')
            return False
        except socket.error as e:
            log.info('connection error', errno=e.errno, reason=e.strerror)
            self.errors.add(address, 'connection error')
            return False
        self._start_peer(connection, address, remote_pubkey)
        return True 
開發者ID:heikoheiko,項目名稱:pydevp2p,代碼行數:22,代碼來源:peermanager.py

示例2: sendall

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def sendall(self, data, flags=0):
        self._checkClosed()
        if self._sslobj:
            if flags != 0:
                raise ValueError(
                    "non-zero flags not allowed in calls to sendall() on %s" %
                    self.__class__)

        try:
            return socket.sendall(self, data, flags)
        except _socket_timeout:
            if self.timeout == 0.0:
                # Raised by the stdlib on non-blocking sockets
                raise SSLWantWriteError("The operation did not complete (write)")
            raise 
開發者ID:leancloud,項目名稱:satori,代碼行數:17,代碼來源:_ssl3.py

示例3: sendall

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def sendall(self, data, flags=0):
        self._checkClosed()
        self.__check_flags('sendall', flags)

        try:
            socket.sendall(self, data)
        except _socket_timeout as ex:
            if self.timeout == 0.0:
                # Python 2 simply *hangs* in this case, which is bad, but
                # Python 3 raises SSLWantWriteError. We do the same.
                raise SSLWantWriteError("The operation did not complete (write)")
            # Convert the socket.timeout back to the sslerror
            raise SSLError(*ex.args) 
開發者ID:leancloud,項目名稱:satori,代碼行數:15,代碼來源:_sslgte279.py

示例4: sendall

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def sendall(self, data, flags=0):
        try:
            socket.sendall(self, data)
        except _socket_timeout as ex:
            if self.timeout == 0.0:
                # Python 2 simply *hangs* in this case, which is bad, but
                # Python 3 raises SSLWantWriteError. We do the same.
                raise SSLError(SSL_ERROR_WANT_WRITE)
            # Convert the socket.timeout back to the sslerror
            raise SSLError(*ex.args) 
開發者ID:leancloud,項目名稱:satori,代碼行數:12,代碼來源:_ssl2.py

示例5: __forwardData

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def __forwardData(self,s,d,o,data_timeout=5*60):
        # TODO: 這裏沒有處理單方向關閉連接的情況。
        try:
            while True:
                try:
                    data=s.recv(65536)
                    #logging.debug(u'len(data)=%s'%len(data))
                    if not data:
                        break
                    o['forward_data_time'] = int(time.time()*1000)
                except _socket.timeout as e:
                    if o['forward_data_time'] + data_timeout > int(time.time()*1000):
                        # 解決下慢速下載長時間無上傳造成讀超時斷開連接的問題
                        continue
                    raise
                d.sendall(data)
        except _socket.timeout as e:
            logging.debug(u'連接長時間無數據,關閉。')
        except _socket.error as e :
            if e.errno == 9:
                # 另一個協程關閉了鏈接。
                pass
            elif e.errno == 10053:
                # 遠端關閉了連接
                logging.debug(u'遠端關閉了連接。')
                pass
            elif e.errno == 10054:
                # 遠端重置了連接
                #TODO: 部分網站直連可以成功,但是中途會重置鏈接。但是 multipath 隻在建立連接部分做測試,並沒有處理建立連接後被重置的情況。。。
                logging.debug(u'遠端重置了連接。')
                pass
            else:
                logging.exception(u'DirectProxy.__forwardData')
        finally:
            # 這裏 和 socks5 Handle 會重複關閉
            logging.debug(u'DirectProxy.__forwardData  finally')
            gevent.sleep(5)
            s.close()
            d.close() 
開發者ID:GameXG,項目名稱:TcpRoute,代碼行數:41,代碼來源:base.py

示例6: __init__

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def __init__(self, timeout=60):
        self.timeout = timeout 
開發者ID:yinghuocho,項目名稱:ghttproxy,代碼行數:4,代碼來源:server.py

示例7: produce_danmaku

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def produce_danmaku(sock, danmaku_queue, is_health=True):
    """Produce danmakus.

    :param sock: the socket object.
    :param danmaku_queue: the queue to recieve danmaku.
    :param is_health: the status of connection
    """
    start = time.time()
    while True:
        end = time.time()
        if end - start > HEARTBEAT_KEEP_TIME:
            start = time.time()
            heartbeat.switch(sock, danmaku_queue, is_health)
        try:
            data = sock.recv(10240)
            if not data:
                break
        except socket.timeout:
            if not is_health:
                print "連接超時,準備重連服務器。。。"
                break
        except socket.error:
            break
        status = process_recieve_data(danmaku_queue, data)
        if status:
            consume_danmaku.switch(sock, danmaku_queue, is_health) 
開發者ID:OctavianLee,項目名稱:Barrage,代碼行數:28,代碼來源:produce_and_consume.py

示例8: heartbeat

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def heartbeat(sock, danmaku_queue, is_health):
    """Keep the connection alive.

    :param sock: the socket object.
    :param danmaku_queue: the queue to recieve danmaku.
    :param is_health: the status of connection
    """
    
    while True:
        try:
            send_data = send_socket_data(sock, 16, 16, 1, 2)
        except socket.timeout:
            is_health = False
        produce_danmaku.switch(sock, danmaku_queue, is_health) 
開發者ID:OctavianLee,項目名稱:Barrage,代碼行數:16,代碼來源:produce_and_consume.py

示例9: test_no_logging_until_many_transient_error

# 需要導入模塊: from gevent import socket [as 別名]
# 或者: from gevent.socket import timeout [as 別名]
def test_no_logging_until_many_transient_error():
    transient = [
        socket.timeout,
        socket.error,
        _mysql_exceptions.OperationalError(
            "(_mysql_exceptions.OperationalError) (1213, 'Deadlock "
            "found when trying to get lock; try restarting transaction')"),
        _mysql_exceptions.OperationalError(
            "(_mysql_exceptions.OperationalError) Lost connection to MySQL "
            "server during query"),
        _mysql_exceptions.OperationalError(
            "(_mysql_exceptions.OperationalError) MySQL server has gone away."),
        _mysql_exceptions.OperationalError(
            "(_mysql_exceptions.OperationalError) Can't connect to MySQL "
            "server on 127.0.0.1"),
        _mysql_exceptions.OperationalError(
            "(_mysql_exceptions.OperationalError) Max connect timeout reached "
            "while reaching hostgroup 71"),
        StatementError(
            message="?", statement="SELECT *", params={},
            orig=_mysql_exceptions.OperationalError(
                "(_mysql_exceptions.OperationalError) MySQL server has gone away.")),
    ]

    for transient_exc in transient:
        logger = MockLogger()
        failing_function = FailingFunction(transient_exc, max_executions=2)
        retry_with_logging(failing_function, logger=logger)

        assert logger.call_count == 0, '{} should not be logged'.format(transient_exc)
        assert failing_function.call_count == 2

        failing_function = FailingFunction(socket.error, max_executions=21)
        retry_with_logging(failing_function, logger=logger)

        assert logger.call_count == 1
        assert failing_function.call_count == 21

        failing_function = FailingFunction(socket.error, max_executions=2) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:41,代碼來源:test_concurrency.py


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