[docs] [issue13354] tcpserver should document non-threaded long-living connections
report at bugs.python.org
Sun Nov 6 10:10:11 CET 2011
New submission from Bas Wijnen <wijnen at debian.org>:
The solution is to create a separate process or thread to handle each request; the ForkingMixIn and ThreadingMixIn mix-in classes can be used to support asynchronous behaviour.
There is another way, which doesn't bring multi-threading hell over you: keep a copy of the file descriptor and use it when events occur. I recall that this suggestion used to be in the documentation as well, but I can't find it anymore. It would be good to add this suggestion to the documentation.
However, there is a thing you must know before you can use this approach: tcpserver calls shutdown() on the socket when handle() returns. This means that the network connection is closed. Even dup2() doesn't keep it open (it lets you keep a file descriptor, but it returns EOF). The solution for this is to override shutdown_request of your handler to only call close_request (or not call anything at all) for sockets which must remain open. That way, as long as there is a reference to the socket, the network connection will not be shut down. Optionally the socket can be shutdown() explicitly when you're done with the connection.
Something like the paragraph above would be useful in the documentation IMO.
assignee: docs at python
nosy: docs at python, shevek
title: tcpserver should document non-threaded long-living connections
type: feature request
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the docs