|filename = 'c:\\Temp\\hello-service.log',|
|level = logging.DEBUG,|
|format = '[helloworld-service] %(levelname)-7.7s %(message)s'|
|class HelloWorldSvc (win32serviceutil.ServiceFramework):|
|_svc_name_ = "HelloWorld-Service"|
|_svc_display_name_ = "HelloWorld Service"|
|self.stop_event = win32event.CreateEvent(None,0,0,None)|
|self.stop_requested = False|
|logging.info('Stopping service ...')|
|self.stop_requested = True|
|logging.info(' ** Hello PyWin32 World ** ')|
|# Simulate a main loop|
|for i in range(0,50):|
|logging.info('A stop signal was received: Breaking main loop ...')|
|logging.info("Hello at %s" % time.ctime())|
|if __name__ == '__main__':|
if in the command prompt and were in the directory of this file,
this script will create the service just fine but when running i get a 1053 error "the service did not respond to the start or control request in a timely fashion"
For future googlers finding this snippet, I had a heck of a time figuring out how to avoid the dreaded 1053 error when trying to start the service (from an executable compiled with pyinstaller).
This snippet appears to be missing the part that actually invokes the main() of the service class when the Windows Service framework runs the executable.
This tutorial is more complete:
The difference is going from this:
This works because when the Service executes all it does is run the executable with no args.
I hope this helps. Good luck!
Thanks! You saved my day.