码迷,mamicode.com
首页 > 编程语言 > 详细

解决Python(2.7)Webserver 局域网内非本机访问时速度极慢

时间:2015-05-09 17:22:57      阅读:765      评论:0      收藏:0      [点我收藏+]

标签:

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 = ""

 

解决Python(2.7)Webserver 局域网内非本机访问时速度极慢

标签:

原文地址:http://www.cnblogs.com/eturn/p/4490606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!