Issue #1164 resolved

bus deadlock joining main thread

Alexey Luchko
created an issue

Hi!

I had to make custom win32 service running cherrypy. While debugging it found that at cherrypy.engine.exit() it hands waiting something (for multiple objects). Log contained "Waiting for thread MainThread." I found Bus.block() waiting for all non-daemon threads at exit.

A workaround could be either tweaking threading.enumerate() before calling engine.exit() or making main thread daemon.

A possible patch attached.

-- Regards, Alex

Comments (2)

  1. Joel Rivera

    I have just experience exactly the same issue and you are right, the thread that execute SvcStop is not the main thread as a work around tried to communicate trough an event and it worked:

        def SvcDoRun(self):
            import servicemanager
            servicemanager.LogMsg(
                   servicemanager.EVENTLOG_INFORMATION_TYPE,
                   servicemanager.PYS_SERVICE_STARTED,
                   (self._svc_name_, ''))
            SITE.web.start(block=False)
            win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
            SITE.web.stop()
    
        def SvcStop(self):
            import servicemanager
            servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                                  servicemanager.PYS_SERVICE_STOPPED,
                                  (self._svc_name_, ''))
            self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
            win32event.SetEvent(self.stop_event)
    

    Anyway I think that your patch will be an improvement for this case and at the same time fix the issue #1101.

  2. Log in to comment