Martin Panter <vadmium...@gmail.com> added the comment:

The change in handling KeyboardInterrupt was my intention in Issue 23430. I 
hope it isn’t a problem on its own :)

Running the module with “python -m http.server” uses the HTTPServer class, 
based on socketserver.TCPServer. This only accepts one connection at a time, 
and waits for the SimpleHTTPRequestHandler class to finish handling each TCP 
connection before shutting it down and waiting for the next one. But 
SimpleHTTPRequestHandler supports persistent HTTP connections, meaning the TCP 
connection stays open after one HTTP request, ready for another. This prevents 
the simple TCPServer from accepting new connections.

What is probably happening is the browser is trying to make one request (e.g. 
for domain3.html) on a new connection while it has an existing persistent 
connection already open. Having multiple host names pointing to the same server 
is not going to help; perhaps the browser does not realize that the two 
connections are to the same TCP server or that it could reuse the old 
connection.

A simple workaround would be to use the socketserver.ThreadingMixIn or 
ForkingMixIn class. Each TCP connection will then be handled in a background 
thread. The mixed-in TCPServer will not wait for the handler, and will accept 
concurrent connections.

If you want to avoid multiple threads, I think it is also possible to augment 
the server and handler classes to use “select” or similar so that the server 
will still handle each HTTP request one at a time, but can wait for requests on 
multiple TCP connections. But it requires subclassing and overriding some 
methods with custom code, and probably depends on deeper knowledge of how the 
classes work than is specified in the documentation.

For existing versions of Python, I don’t there is much that could be done other 
than documenting the shortcomings of how a persistent HTTP connection vs 
multiple connections is handled.

----------
nosy: +martin.panter

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31639>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to