Python 3.5 amd64 and win32service
Nagy László Zsolt
gandalf at shopzeus.com
Tue Oct 4 03:33:20 EDT 2016
>> Is it possible to write a win32 service with 64 bit python 3.5? The
>> pywin32 package does exist on 3.5 64bit, but missing some modules:
> Try pip installing the "pypiwin32" package.
That worked, thanks.
Do you have an explanation why to official build (
https://sourceforge.net/projects/pywin32/files/pywin32/ ) is missing
these module? I'm curious.
After installing this package, the "service start" operation throws "The
Service Did Not Respond To The Start Or Control Request In A Timely
Fashion". error code 1053
I have written many other win32 services in python2 before, but never
got this error message. Is this specific to windows 10?
Here is an MWE:
#!/usr/bin/python3
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import threading
import time
class AppServerSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "TestService"
_svc_display_name_ = "Test Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.stop_requested = threading.Event()
self.stop_requested.clear()
socket.setdefaulttimeout(60)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
self.main()
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def main(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
while not self.stop_requested.is_set():
time.sleep(1) # So something useful here
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)
More information about the Python-list
mailing list