Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'handler': 0.05; 'debug': 0.07; 'detect': 0.07; 'patterns.': 0.07; 'remaining': 0.07; 'defines': 0.09; 'http': 0.09; 'naturally': 0.09; 'page)': 0.09; 'subject:page.': 0.09; 'sure,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'itself.': 0.14; '570': 0.16; 'displayed.': 0.16; 'firebug': 0.16; 'reedy': 0.16; 'resource.': 0.16; 'subject: \n ': 0.16; 'subject:after': 0.16; 'wrote:': 0.18; 'module': 0.19; 'slightly': 0.19; 'example': 0.22; 'import': 0.22; '(in': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'sends': 0.24; 'header': 0.24; 'server.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; "i've": 0.25; 'second': 0.26; 'post': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'compared': 0.30; 'statement': 0.30; '(which': 0.31; 'code': 0.31; 'reply.': 0.31; 'requests': 0.31; '13,': 0.31; 'doc': 0.31; 'post.': 0.31; 'question:': 0.31; 'safely': 0.31; 'class': 0.32; 'says': 0.33; 'running': 0.33; 'skip:# 10': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'connection': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'thanks': 0.36; 'possible': 0.36; 'should': 0.36; 'so,': 0.37; 'being': 0.38; 'server': 0.38; 'skip:m 40': 0.38; 'resource': 0.38; 'does': 0.39; 'how': 0.40; 'simple,': 0.60; 'increased': 0.61; 'browser': 0.61; 'first': 0.61; 'taking': 0.65; 'finish': 0.65; 'charset:windows-1252': 0.65; 'default': 0.69; 'request.': 0.70; 'behavior': 0.77; '3.3.1': 0.84; 'isn\x92t': 0.84; 'ridiculously': 0.84; 'this...': 0.84; 'instantly.': 0.91; 'subject:skip:S 20': 0.91; 'whereas': 0.91; 'hand,': 0.93; 'directly.': 0.95; '2013': 0.98 X-Received: by 10.49.132.196 with SMTP id ow4mr41012qeb.28.1365873680861; Sat, 13 Apr 2013 10:21:20 -0700 (PDT) Newsgroups: comp.lang.python Date: Sat, 13 Apr 2013 10:21:20 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.238.76.128; posting-account=RvHFJQoAAABjGPM8XlLh6XgKam0WFBaf References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 213.238.76.128 MIME-Version: 1.0 Subject: Re: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page. From: Piotr Dobrogost To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365874188 news.xs4all.nl 2598 [2001:888:2000:d::a6]:56178 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43531 On Saturday, April 13, 2013 12:21:33 AM UTC+2, Terry Jan Reedy wrote: > I find the doc slightly confusing. The SO code uses BaseHTTPServer. The= =20 > doc says "Usually, this module isn=92t used directly," On the other hand,= =20 > SimpleHTTPServer only defines a request handler and not a server itself. Thanks for taking time to reply. Well, I've seen presentations where BaseHTTPServer is a recommended way of = running simple, ad-hoc web server. In addition the documentation of http.se= rver module in Python 3.3 (which contains implementation of the same HTTPSe= rver class as found in BaseHTTPServer module in Python 2.x) does not contai= n the statement you cited which I take to mean it can safely be used direct= ly. As Python 3.3.1 exhibits the same behavior let's focus on the following Pyt= hon 3 version of the code from the original question: from http.server import SimpleHTTPRequestHandler from http.server import HTTPServer class MyRequestHandler(SimpleHTTPRequestHandler): #protocol_version =3D "HTTP/1.0" # works protocol_version =3D "HTTP/1.1" # hangs server =3D HTTPServer(("localhost", 7080), MyRequestHandler) server.serve_forever() > What does 'hang' mean? Does the page get displayed? If so,=20 > server.serve_forever is supposes to 'hang'. I increased the number of resources to 7 to be able to detect possible patt= erns. The page and some of the resources are being displayed almost instant= ly. However browser waits for the requests to get remaining resources to fi= nish and so those resources naturally are not being displayed. When browser= waits the code is stuck at the line I showed in my original post. What's i= nteresting is that after some time the request to get the second resource (= in case there are only 2 on the page) finishes. However the time spent wait= ing for the second resource is ridiculously long compared to time spend wai= ting for the first resource. For example in one of my tests Firebug showed = waiting time for the first resource to be 4ms whereas the waiting time for = the second resource to be 1m 55s. > The SO post says >=20 > class MyRequestHandler(SimpleHTTPRequestHandler): > #protocol_version =3D "HTTP/1.0" # works > protocol_version =3D "HTTP/1.1" # hangs >=20 > so this should be some sort of clue. The code says >=20 > 569 # The version of the HTTP protocol we support. > 570 # Set this to HTTP/1.1 to enable automatic keepalive > 571 protocol_version =3D "HTTP/1.0" Sure, in version 1.1 of http the connection is not closed by default unless= 'Connection: Close' header was sent in request. Firefox sends all requests= with 'Connection: keep-alive' header. I don't really know how to debug this...