Python 服务可以';启动时不能启动,但可以手动启动
我有一个使用servicemanager的python项目,我使用pyinstaller将其构建为exe。一切工作正常,我已经安装它作为窗口服务 我已设置服务启动类型:自动(延迟启动) 但当我重新启动计算机时,服务并没有启动,我必须转到服务并手动启动它 我查看事件查看器,它会显示:Python 服务可以';启动时不能启动,但可以手动启动,python,service,pyinstaller,Python,Service,Pyinstaller,我有一个使用servicemanager的python项目,我使用pyinstaller将其构建为exe。一切工作正常,我已经安装它作为窗口服务 我已设置服务启动类型:自动(延迟启动) 但当我重新启动计算机时,服务并没有启动,我必须转到服务并手动启动它 我查看事件查看器,它会显示: The instance's SvcRun() method failed <Error getting traceback - traceback.print_exception() failed %2:
The instance's SvcRun() method failed
<Error getting traceback - traceback.print_exception() failed
%2: %3
对不起,信息不对。上面的错误是我测试服务时的旧错误 错误是:
等待TestService服务连接时超时(30000毫秒)。
增加窗口服务的超时时间将解决这个问题这看起来可能是相关的(请参阅对问题的评论)。我有带tcp套接字的测试服务管理器,它工作正常。重新启动时启动服务。也许问题出在tornado或asyncio上。
app = tornado.web.Application([
(r'/', WebSocketHandler),
])
class TestService(win32serviceutil.ServiceFramework):
_svc_name_ = "SignMatchService"
_svc_display_name_ = "SignMatchService"
_svc_description_ = "The service match signature"
def log(self, msg):
import servicemanager
servicemanager.LogInfoMsg(str(msg))
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(150)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
_init_asyncio_patch()
tornado.ioloop.IOLoop.instance().stop()
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
def SvcDoRun(self):
global sig_matcher
self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
try:
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
_init_asyncio_patch()
asyncio.set_event_loop(asyncio.new_event_loop())
app.listen(5555)
tornado.ioloop.IOLoop.instance().start()
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
except Exception as x:
print('Exception : %s\n' % x)
self.SvcStop()
if __name__ == '__main__':
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(TestService)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(TestService)