I apologize -- I opened a ticket for this, and probably should have
posted to the mailing list first. I'm wondering if anyone else has
bumped into this issue, and if I'm missing something obvious.
I am attempting to make a python windows service using the pywin32
libraries. The service works when I install it using pywin32's
PythonService.exe. It also seems to work (at least on the surface)
when I make an exe using pyinstaller.
When using pyinstaller, I'm able to install and start my service
without an issue. When I shut down the service, the application
appears to stop as well. However, I get a strange error on the
console (using win32's win32traceutil.py), as follows:
"Exception KeyError: KeyError(2244,) in <module 'threading' from
'2\build\pyi.win32\agentservice\outPYZ1.pyz/threading'> ignored"
When I strip my service down to its most basic components, I find that
simply importing the python logging module is causing the error. The
error only occurs on shut down (so the import itself doesn't throw an
exception). No errors are logged to the windows event log.
My setup:
- Python 2.6.6
- Pyinstaller 1.5.1
- Pywin32 build 217
- Windows XP
Here's what my code looks like. If the logging module below (in
SvcDoRun) is commented out, the error disappears.
-------------------------------------------------------
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)
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyinstaller?hl=en.