Windows service code gives thread error when using Pywin32 / PyInstaller
I am getting an error when using python exe generated from pyinstaller to create windows service. The error message can be harmless and doesn't seem to affect the service, but I'm not sure if there are other issues going on behind the scenes. I am using pywin32 libraries to install an application as a windows service. I should note that I am not getting this error when installing from the python script itself, using PythonService.exe from pywin32, only from the executable generated with pyinstaller.
When using pyinstaller, I can generate an exe from my windows service code and install it, no problem. I can also start the service, no problem. I can even stop the service and the application appears to be closed. However, as soon as I initiated the stop, I get the following error in the console when running win32traceutil.py:
"Exception KeyError: KeyError(2244,) in <module 'threading' from '2\build\pyi.win32\agentservice\outPYZ1.pyz/threading'> ignored"
No errors are recorded in the event log. I was able to trace it back to the python registration module. Just importing the logging module seems to be causing my problem. Commenting out the import eliminates the error. It seems pretty clear to me that this is causing the problem, but it seems strange to me that pyinstaller would have problems with a module in the standard library. Does anyone else come across this?
I am running Python 2.6.6, Pyinstaller 1.5.1, Build 217 from Pywin32. I am on Windows XP.
And a stripped down version of my code:
import win32service import win32serviceutil import win32event import win32evtlogutil import win32traceutil import servicemanager import sys import os import time class myservice(win32serviceutil.ServiceFramework): _svc_name_ = "5" _svc_display_name_ = "5" _svc_deps_ = ["EventLog"] def __init__(self, args): self.isAlive = True win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) def event_log(self, msg): servicemanager.LogInfoMsg(str(msg)) def SvcStop(self): # tell Service Manager we are trying to stop (required) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) print "svcstop: stopping service, setting event" # set the event to call win32event.SetEvent(self.hWaitStop) print "svcstop: ending svcstop" def SvcDoRun(self): print "we are starting the service..." self.event_log("Starting %s" % self._svc_name_) ############ IF LOGGING IS COMMENTED OUT, THE ERROR GOES AWAY################ import logging print "svcdorun: waiting for object" win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE) print "svcdorun: return from function" if __name__ == '__main__': if len(sys.argv)==1: import win32traceutil print "service is starting..." #servicemanager.Initialize() servicemanager.Initialize('backup service', None) servicemanager.PrepareToHostSingle(myservice) # Now ask the service manager to fire things up for us... servicemanager.StartServiceCtrlDispatcher() print "service done!" else: win32serviceutil.HandleCommandLine(myservice)
source to share
No one has answered this question yet
Check out similar questions: