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()

authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
changeset891cdb7d8cbb
branchstable
phasepublic
hiddenno
parent revision#2ea98b8512dd [events manager] onevent decorator may be given extra arguments to give to em.bind
child revision#289cb1cebae8 merge
files modified by this revision
etwist/service.py
# HG changeset patch
# User Alexandre Fayolle <alexandre.fayolle@logilab.fr>
# Date 1269959372 -7200
# Tue Mar 30 16:29:32 2010 +0200
# Branch stable
# Node ID 891cdb7d8cbbf862bcfb613c003890c7a606966e
# Parent 2ea98b8512ddbfcf40406ca3ec699f436f71d25f
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()

diff --git a/etwist/service.py b/etwist/service.py
@@ -15,28 +15,26 @@
1  logger.handlers = [handlers.NTEventLogHandler('cubicweb')]

2 
3  os.environ['CW_INSTANCES_DIR'] = r'C:\etc\cubicweb.d'

4  os.environ['USERNAME'] = 'cubicweb'

5 
6 -

7  class CWService(object, win32serviceutil.ServiceFramework):

8      _svc_name_ = None

9      _svc_display_name_ = None

10      instance = None

11 
12      def __init__(self, *args, **kwargs):

13          win32serviceutil.ServiceFramework.__init__(self, *args, **kwargs)

14 -        self._stop_event = win32event.CreateEvent(None, 0, 0, None)

15          cwcfg.load_cwctl_plugins()

16          set_log_methods(CubicWebRootResource, logger)

17          server.parsePOSTData = parsePOSTData

18 
19      def SvcStop(self):

20          self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

21          logger.info('stopping %s service' % self.instance)

22 -        win32event.SetEvent(self._stop_event)

23 -        self.ReportServiceStatus(win32service.SERVICE_STOPPED)

24 +        reactor.stop()

25 +        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

26 
27      def SvcDoRun(self):

28          self.ReportServiceStatus(win32service.SERVICE_START_PENDING)

29          logger = getLogger('cubicweb.twisted')

30          logger.info('starting %s service' % self.instance)

@@ -55,7 +53,6 @@
31              self.ReportServiceStatus(win32service.SERVICE_RUNNING)

32              reactor.run()

33          except Exception, e:

34              logger.error('service %s stopped (cause: %s)' % (self.instance, e))

35              logger.exception('what happened ...')

36 -            self.SvcStop()

37 -

38 +        self.ReportServiceStatus(win32service.SERVICE_STOPPED)