Problem in multithreading Socketserver explained (should apply to *nix, too)
brueckd at tbye.com
brueckd at tbye.com
Wed Aug 29 12:19:53 EDT 2001
On Wed, 29 Aug 2001, Michael Abbott wrote:
> > def handle_request(self):
> > try:
> > request, client_address = self.get_request()
> > except socket.error:
> > return
> > if self.verify_request(request, client_address):
> > try:
> > # this will start a new thread
> > self.process_request(request, client_address)
> > except:
> > self.handle_error(request, client_address)
> > # this will close the socket still in use by the new thread
> > self.close_request(request)
What version of Python is this? 1.5.2 and 2.0 don't have the close_request
call at all. Python 2.1.1 has:
...
try:
self.process_request(request, client_address)
except:
self.handle_error(request, client_address)
self.close_request(request)
Note the indentation - the close_request call happens only after an
exception gets raised, and so the threading mix-in works fine. Has yours
been modified or do I just have a different version than you?
> > Solution:
Instead of that long solution why don't you just change the indentation of
close_request? Or, subclass TCPServer and implement your own
handle_request that doesn't call close_request at the end. Then you can
use the threading mixin. Either way, it's a lot less work.
-Dave
More information about the Python-list
mailing list