Problem in multithreading Socketserver explained (should appl y to *nix, too)

brueckd at brueckd at
Thu Aug 30 16:55:52 CEST 2001

On Thu, 30 Aug 2001, Michael Abbott wrote:

> (I'm not on python-list; evidently need to change this.  In fact, where is
> this list?  It doesn't appear on

Hi Michael,
It is on that page, you just have to look way down towards the bottom.

> This is the source in my version of Python: the interpreter comes up
> reporting
> Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32

So maybe it was an indentation bug fixed between 2.1 and 2.1.1. I'll go
look at the CVS look on SF.

> I don't understand the solution you're describing, unless process_request is
> now guaranteed to call close_request.

Why do you need to call close_request at all? The socket gets closed
automagically when your handler finishes. (Personally I'd prefer that the
call to close_request *does* happen just so it's explicit, but it works
either way).

> The 2.1.1 solution you quote doesn't look right to me, in particular cleanup
> and error handling in the presence of a separate thread looks doubtful.

As I mentioned above, missing the call to close_request isn't really
causing you much pain - the real problem was the incorrect indentation in
your version of

No doubt your solution will work just fine; I was just pointing out that
there's probably a much easier way since, for the most part, SocketServer
works just fine. For example, assuming you've fixed the indentation
problem, your only other problem was the missing call to handle_error in
the separate thread, right? So (untested):

class YourServer(ThreadingMixIn, HTTPServer):
  def finish_request(self, request, client_address):
      self.RequestHandlerClass(request, client_address, self)
      self.handle_error(request, client_address)
    self.close_request(request) # Just for good measure

That's it, 7 lines of code and you're done.
Have fun,

More information about the Python-list mailing list