Python windows service "Error starting service: The service did not respond to the start or control request in a timely fashion"
It's possible that your service is not starting because it's unable to find the executable. I had a similar issue that was solved by adding some pywin32 related directories to my system path. You can do this using setx
:
setx /M PATH "%PATH%;C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages\pywin32_system32;C:\Python27\Lib\site-packages\win32"
Try running this in a cmd window with admin privileges and adjust the paths to match your own python installation.
Finally, the solution for this.
First step:
USE pyinstaller to create a standalone executable file, i.e.:
pip install pyinstaller pyinstaller yourproject.py cd dist\yourproject yourproject.exe install
Second step:
Note that. When the Windows Service calls "your program", it gives a time to answer according the Service Development Protocol. All of the codes above, are not starting the service. Please, change your code as below:
if __name__ == '__main__': if len(sys.argv) > 1: # Called by Windows shell. Handling arguments such as: Install, Remove, etc. win32serviceutil.HandleCommandLine(JobManager) else: # Called by Windows Service. Initialize the service to communicate with the system operator servicemanager.Initialize() servicemanager.PrepareToHostSingle(JobManager) servicemanager.StartServiceCtrlDispatcher()