This is what I do:
Instead of instancing directly the class BaseHTTPServer.HTTPServer, I write a new descendant from it that publishes an "stop" method:
class AppHTTPServer (SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
def serve_forever(self):
self.stop_serving = False
while not self.stop_serving:
self.handle_request()
def stop (self):
self.stop_serving = True
And then, in the method SvcStop that you already have, I call that method to break the serve_forever() loop:
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.httpd.stop()
(self.httpd is the instance of AppHTTPServer() that implements the webserver)
If you use setDaemon() correctly on the background threads, and interrupt correctly all the loops in the service, then the instruction
exit(0)
in SvcStop() should not be necessary
Ricardo Reyes
2008-09-30 19:47:49