This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author shevek
Recipients docs@python, shevek
Date 2011-11-06.09:10:10
SpamBayes Score 9.117336e-08
Marked as misclassified No
Message-id <1320570611.72.0.286817751979.issue13354@psf.upfronthosting.co.za>
In-reply-to
Content
http://docs.python.org/py3k/library/socketserver.html says:

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.
History
Date User Action Args
2011-11-06 09:10:11sheveksetrecipients: + shevek, docs@python
2011-11-06 09:10:11sheveksetmessageid: <1320570611.72.0.286817751979.issue13354@psf.upfronthosting.co.za>
2011-11-06 09:10:11sheveklinkissue13354 messages
2011-11-06 09:10:10shevekcreate