From 449673c87581e6941ba3ceefda9ca12815503e0f Mon Sep 17 00:00:00 2001 From: Phus Lu Date: Fri, 11 May 2012 22:44:10 +0800 Subject: [PATCH] disable ThreadingTCPServer dns revsere lookup, sometimes it will be slow --- local.py | 7 +++++-- server.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/local.py b/local.py index 00095d1..4c60191 100755 --- a/local.py +++ b/local.py @@ -34,6 +34,9 @@ import threading import time import SocketServer +#disable ThreadingTCPServer dns revsere lookup, sometimes it will be slow +socket.getfqdn = lambda x:x + def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): """python 2.7 socket.create_connection""" @@ -51,14 +54,14 @@ def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, sock.connect(sa) return sock - except socket.error as _: + except error as _: err = _ if sock is not None: sock.close() if err is not None: raise err else: - raise error("getaddrinfo returns an empty list") + raise socket.error("getaddrinfo returns an empty list") def get_table(key): m = hashlib.md5() diff --git a/server.py b/server.py index a37293e..97487e9 100755 --- a/server.py +++ b/server.py @@ -37,6 +37,9 @@ import string import hashlib import sys +#disable ThreadingTCPServer dns revsere lookup, sometimes it will be slow +socket.getfqdn = lambda x:x + def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None): """python 2.7 socket.create_connection""" @@ -61,7 +64,7 @@ def socket_create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, if err is not None: raise err else: - raise error("getaddrinfo returns an empty list") + raise socket.error("getaddrinfo returns an empty list") def get_table(key): m = hashlib.md5()