我使用Pyinstaller创建了Flask应用程序作为windows服务。我在本地计算机(Windows 10)上安装了它。工作正常。我试图在Windows server中安装的同一个exe已安装但未运行,并引发错误, 错误1053:服务未及时响应启动或控制请求
这是我的服务代码
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)
windows 10中用于创建服务exe的库版本: Python-3.6.3 Pyinstaller-4.2
Windows Server 2012 R2-Python 3.6.8
在windows server中,我的python版本不同。我已经验证了环境路径。 如果问题出在不同版本的python上,那么我在另一台windows 10机器上安装的同一个服务使用python 3.6.7。服务很好
谁能告诉我这里有什么错误,我遗漏了什么?任何帮助都将不胜感激
目前没有回答
相关问题 更多 >
编程相关推荐