How can I kill CGIHTTPServer ?

E

eching

I'm running CGIHTTPServer with the serve_forever method and I cannot
get the darn thing to stop unless I kill the command prompt its
running in. I searched for similar posts here and found this:

http://groups.google.com/group/comp...67?lnk=gst&q=HTTPServer+kill#ff7d0aa2be964767

But there doesn't seem to be a definitive answer. I tried one of the
last proposed solutions:

class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pause = 0.25
allow_reuse_address = True

def __init__(self, server_address, RequestHandlerClass):
SocketServer.TCPServer.__init__(self, server_address,
RequestHandlerClass)
self.socket.settimeout(self.pause)
self.serving = 1
...

def serve_forever(self):
while self.serving:
self.handle_request()

And that worked, but the last post in the thread suggested '...this
would cause timeouts in the middle of handling request whenever a
client is slow'

Can anyone comment on this solution or have other possible solutions?
Eventually I probably will want this to run as a windows service to
serve up some internal apps, so it would be great if I could the
server to shutdown gracefully.

Thanks in advance,
Eric
 
S

Steve Holden

eching said:
I'm running CGIHTTPServer with the serve_forever method and I cannot
get the darn thing to stop unless I kill the command prompt its
running in. I searched for similar posts here and found this:

http://groups.google.com/group/comp...67?lnk=gst&q=HTTPServer+kill#ff7d0aa2be964767

But there doesn't seem to be a definitive answer. I tried one of the
last proposed solutions:

class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pause = 0.25
allow_reuse_address = True

def __init__(self, server_address, RequestHandlerClass):
SocketServer.TCPServer.__init__(self, server_address,
RequestHandlerClass)
self.socket.settimeout(self.pause)
self.serving = 1
...

def serve_forever(self):
while self.serving:
self.handle_request()

And that worked, but the last post in the thread suggested '...this
would cause timeouts in the middle of handling request whenever a
client is slow'

Can anyone comment on this solution or have other possible solutions?
Eventually I probably will want this to run as a windows service to
serve up some internal apps, so it would be great if I could the
server to shutdown gracefully.

Thanks in advance,
Eric

It really might be a good idea to patch serve_forever in the library to
allow handlers to raise a specific StopServing exception. At the moment
IIRC the position is that there's a generic trap of pretty much all
exceptions, which isn't too helpful. I suppose a counter-argument might
be that "forever" has a defined meaning, and the method is correctly
named, but that's mere semantics.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top