I have created Flask Application as windows service by using Pyinstaller. I installed it in my local machine(Windows 10). Its working fine. The same exe I tried to install in Windows server, it is installed but not running and throwing error, Error 1053: The service did not respond to the start or control request in a timely fashion.
Here's my code for service.
class FlaskTestServiceSVC (win32serviceutil.ServiceFramework):
_svc_name_ = "Flask Test Service"
_svc_display_name_ = "Flask Test Service"
_svc_description_ = "Flask Test Service"
def __init__(self, *args):
win32serviceutil.ServiceFramework.__init__(self, *args)
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
socket.setdefaulttimeout(5)
self.stop_requested = False
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
self.stop_requested = True
def SvcDoRun(self):
rc = None
while rc != win32event.WAIT_OBJECT_0:
try:
serve(app, host=config.ip_address, port=config.port)
except Exception as e:
print(e)
rc = win32event.WaitForSingleObject(self.hWaitStop, 5000)
if __name__ == '__main__':
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(FlaskTestServiceSVC)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(FlaskTestServiceSVC)
Library versions in windows 10 I used to create Service exe: Python - 3.6.3 Pyinstaller - 4.2
Windows Server 2012 R2 - Python 3.6.8
In windows server, my python version is different. I have verified the environment paths. If the problem with the different versions of python, then the same service I installed in another windows 10 machine with Python 3.6.7. The service is working fine.
Could anyone tell me what is there error here and what am I missing? Any help would be really appreciated.