From 6e30a04bbe384269fa6a2d51a0a491a0a10b6e69 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 18 May 2018 14:21:59 +0200 Subject: browse.py: fix delay with multiple connections When Firefox opens two TCP connections and sends a request over the second connection, it is not processed until the first one is closed. Use a threaded server to solve this issue. Tested with Python 2.7.15 and 3.6.5. (Also tested with 2.6, but that failed due to lack of argparse.) Link: https://bugs.python.org/issue31639 --- src/browse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/browse.py b/src/browse.py index 64a16f2..1c9c39b 100755 --- a/src/browse.py +++ b/src/browse.py @@ -24,8 +24,10 @@ from __future__ import print_function try: import http.server as httpserver + import socketserver except ImportError: import BaseHTTPServer as httpserver + import SocketServer as socketserver import argparse import cgi import os @@ -205,10 +207,14 @@ parser.add_argument('-f', default='build.ninja', parser.add_argument('initial_target', default='all', nargs='?', help='Initial target to show (default %(default)s)') +class HTTPServer(socketserver.ThreadingMixIn, httpserver.HTTPServer): + # terminate server immediately when Python exits. + daemon_threads = True + args = parser.parse_args() port = args.port hostname = args.hostname -httpd = httpserver.HTTPServer((hostname,port), RequestHandler) +httpd = HTTPServer((hostname,port), RequestHandler) try: if hostname == "": hostname = socket.gethostname() -- cgit v0.12