python设定并获取socket超时时间

1.python写法

  1. 
    
    import socket
     
    def test_socket_timeout():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print "Default socket timeout: %s" %s.gettimeout()
        s.settimeout(100)
        print "Current socket timeout: %s" %s.gettimeout()
        
    if __name__ == '__main__':
        #针对单个socket实例的超时
        test_socket_timeout()
    

猜你喜欢

转载自blog.csdn.net/qq_35843543/article/details/81487764