解决Python(2.7)Webserver 局域网内非本机访问时速度极慢
from wsgiref.simple_server import * def aaa(environ,start_response): # try: # request_body_size = int(environ.get(‘CONTENT_LENGTH‘, 0)) # except (ValueError): # request_body_size = 0 # request_body = environ[‘wsgi.input‘].read(request_body_size) # print request_body+"#" start_response("200 OK",[(‘content-type‘,"text/html")]) return [‘aaaa‘] if __name__ == ‘__main__‘: httpd = make_server(‘‘, 80, aaa,WSGIServer,WSGIRequestHandler) sa = httpd.socket.getsockname() print ‘http://{0}:{1}/‘.format(*sa) # Respond to requests until process is killed httpd.serve_forever()
原因在于
C:\Python27\Lib\BaseHTTPServer.py
def address_string(self): host, port = self.client_address[:2] return socket.getfqdn(host)#very slow here
print socket.getfqdn("192.168.1.101")#这里要用10秒左右
解决:
修改C:\Python27\Lib\wsgiref\simple_server.py
host = self.address_string()#very slow here 改为 host = ""
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。