New submission from Bas Wijnen <wij...@debian.org>:

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.

----------
assignee: docs@python
components: Documentation
messages: 147147
nosy: docs@python, shevek
priority: normal
severity: normal
status: open
title: tcpserver should document non-threaded long-living connections
type: feature request
versions: Python 3.2

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

Reply via email to