[Pythonmac-SIG] thread blocking problem?
John P Speno
speno at isc.upenn.edu
Fri Oct 17 14:29:55 EDT 2003
On Fri, Oct 17, 2003 at 12:14:05PM -0600, William McLendon wrote:
> I'm pretty new with this... What the differences in these are? Critical
> issues, etc?
The differences are that the base HTTPServer can only process one request
at a time while the forking and threading servers can process more than one
at a time. The ForkingTCPServer creates a new child process to handle each
request, while the ThreadingTCPServer uses a new thread per request. You may
want to read the SocketServer.py module for the details.
Another technique for doing this in one process or thread is the event driven
module used by Twisted and Medusa for example.
> Is Python's fork()ing incomplete?
I'm not sure what you mean by that.
> Any workarounds?
Modify the HTTPServer class from BaseHTTPServer.py to inherit from
Create your own server class like this (stolen from BaseHTTPServer.py:
class ForkingHTTPServer(SocketServer.ForkingTCPServer):
allow_reuse_address = 1 # Seems to make sense in testing environment
def server_bind(self):
"""Override server_bind to store the server name."""
SocketServer.TCPServer.server_bind(self)
host, port = self.socket.getsockname()
self.server_name = socket.getfqdn(host)
self.server_port = port
And even this will probably work:
class ForkingHTTPServer(BaseHTTPServer.HTTPServer, SocketServer.ForkingMixIn):
pass
Then just define your server like this:
server = ForkingHTTPServer(('127.0.0.1', 2000), httpRequestHandler)
None of this is specific to python on the Mac, but I'm not sure how well
OS 9 handles either fork or threads. There's no problem on OS X.
More information about the Pythonmac-SIG
mailing list