【发布时间】:2021-10-08 05:48:39
【问题描述】:
我在 python 中创建了一个 windows 服务,然后将其转换为一个 exe 文件,并使用此命令将该 exe 文件安装为 windows 服务:
sc create PC-Service binpath= "C:\\Users\\Slazenger\\Desktop\\auto-py-to-exe-master\\output\\testing.exe" DisplayName= "PC-Service" start=auto
我收到了成功消息
[SC] CreateService SUCCESS
但是当我尝试使用此命令安装服务时:
sc start PC-Service
我收到此错误消息
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
我不知道为什么我会得到这个,因为当我 运行我的 python 脚本作为服务时它运行完美,但是当我尝试将 exe 文件作为服务运行时出现错误,请帮助我。 这是我的python脚本:
def WriteToFile():
while True:
file = open ( "C:\\file.txt" , "w" )
now = datetime.now()
now = now.strftime("%B %d, %y %H:%M:%S")
file.write(now)
class Pythonservice(win32serviceutil.ServiceFramework):
_svc_name_ = 'PC-Service'
_svc_display_name_ = 'PC-Service'
_svc_description_ = 'Freindly Service'
@classmethod
def parse_command_line(cls):
win32serviceutil.HandleCommandLine(cls)
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.stop()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
self.start()
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ''))
self.main()
def start(self):
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
WriteToFile()
if __name__ == '__main__':
Pythonservice.parse_command_line()
请帮我摆脱这个谢谢。
【问题讨论】: