handle Service Close request correctly (closes #736039) stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Tue, 30 Mar 2010 16:29:32 +0200
branchstable
changeset 5088 891cdb7d8cbb
parent 5081 2ea98b8512dd
child 5089 289cb1cebae8
handle Service Close request correctly (closes #736039) The windows event self._stop_event was not used, and twisted was not getting a chance of terminating cleanly by calling its shutdown event handlers (which would eventually call pyro_unregister). Fixed by calling reactor.stop()
etwist/service.py
--- a/etwist/service.py	Tue Mar 30 13:32:01 2010 +0200
+++ b/etwist/service.py	Tue Mar 30 16:29:32 2010 +0200
@@ -17,7 +17,6 @@
 os.environ['CW_INSTANCES_DIR'] = r'C:\etc\cubicweb.d'
 os.environ['USERNAME'] = 'cubicweb'
 
-
 class CWService(object, win32serviceutil.ServiceFramework):
     _svc_name_ = None
     _svc_display_name_ = None
@@ -25,7 +24,6 @@
 
     def __init__(self, *args, **kwargs):
         win32serviceutil.ServiceFramework.__init__(self, *args, **kwargs)
-        self._stop_event = win32event.CreateEvent(None, 0, 0, None)
         cwcfg.load_cwctl_plugins()
         set_log_methods(CubicWebRootResource, logger)
         server.parsePOSTData = parsePOSTData
@@ -33,8 +31,8 @@
     def SvcStop(self):
         self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
         logger.info('stopping %s service' % self.instance)
-        win32event.SetEvent(self._stop_event)
-        self.ReportServiceStatus(win32service.SERVICE_STOPPED)
+        reactor.stop()
+        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 
     def SvcDoRun(self):
         self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
@@ -57,5 +55,4 @@
         except Exception, e:
             logger.error('service %s stopped (cause: %s)' % (self.instance, e))
             logger.exception('what happened ...')
-            self.SvcStop()
-
+        self.ReportServiceStatus(win32service.SERVICE_STOPPED)