我在python中编写了一个Windows服务.如果我从命令提示符运行我的脚本
python runService.py
Run Code Online (Sandbox Code Playgroud)
当我这样做时,服务安装并正确启动.我一直在尝试使用pyinstaller创建一个可执行文件,因为我已经看到了与py2exe相同的问题.当我运行.exe时,服务安装但不启动,我收到以下错误
error 1053 the service did not respond to the start or control request in a timely fashion
Run Code Online (Sandbox Code Playgroud)
我已经看到很多人都有这个问题,但我似乎无法找到关于如何解决这个问题的明确答案.
winservice.py
from os.path import splitext, abspath
from sys import modules, executable
from time import *
import win32serviceutil
import win32service
import win32event
import win32api
class Service(win32serviceutil.ServiceFramework):
_svc_name_ = '_unNamed'
_svc_display_name_ = '_Service Template'
_svc_description_ = '_Description template'
def __init__(self, *args):
win32serviceutil.ServiceFramework.__init__(self, *args)
self.log('init')
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
#logs into the system event log
def log(self, msg):
import …
Run Code Online (Sandbox Code Playgroud)