Hi All
I have a windows service (attached file). I basically just calls another
script every 60 seconds. I can install, start and stop this service as
expected with:
ParseMailboxService.py install | start | stop
The problem is: if I create an exe of this script (all required modules
are included in the exe) with gui2exe (a frontend to py2exe) I can
install the service - but not start it. The error it returns is "Error
starting service: The service did not respond to the start or control
request in a timely fashion."
Is there something I need to additionally include in the compiled exe? I
have manually included the following modules:
* servicemanager
* win32con
* win32evtlogutil
* win32serviceutil
I would greatly appreciate any help.
Regards
Nicol
--
The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle.
#!/usr/bin/env python
import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import os
class aservice(win32serviceutil.ServiceFramework):
_svc_name_ = "ParseMailBox"
_svc_display_name_ = "ParseMailbox - Monitors a POP mail box and parses its emails and attachments."
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
pathtoparsemailbox = "C:\\ParseMailbox\\ParseMailbox.exe"
import servicemanager
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,\
servicemanager.PYS_SERVICE_STARTED,\
(self._svc_name_, ''))
self.timeout = 60000 # 60 Seconds
while 1:
# Wait for service stop signal, if I timeout, loop again
rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
# Check to see if self.hWaitStop happened
if rc == win32event.WAIT_OBJECT_0:
# Stop signal encountered
break
else:
stdin, stdout, stderr = os.popen3( pathtoparsemailbox )
parsemailboxresult = stdout.read()
parsemailboxerrors = stderr.read()
if parsemailboxerrors.strip() != "":
servicemanager.LogErrorMsg("An error occurred when running ParseMailbox (Please see ServiceLog.log for more details):\n" + parsemailboxerrors)
stdin.close(); stdout.close(); stderr.close()
# Only return from SvcDoRun when you wish to stop
return
def SvcStop(self):
# Before we do anything, tell Service Control Manager we are starting the stop process.
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
return
def ctrlHandler(ctrlType):
return True
if __name__ == '__main__':
win32api.SetConsoleCtrlHandler(ctrlHandler, True)
win32serviceutil.HandleCommandLine(aservice)
--
http://mail.python.org/mailman/listinfo/python-list