gpt4 book ai didi

Python win32 服务

转载 作者:太空宇宙 更新时间:2023-11-03 13:23:52 26 4
gpt4 key购买 nike

我有一个最小的 python win32 服务 service.py 没有什么特别的:

import win32serviceutil
import win32service
import win32event

class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "display service"
# _svc_description_='ddd'

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)

if __name__=='__main__':
win32serviceutil.HandleCommandLine(SmallestPythonService)

当我运行时:

 service.py install
service.py start

它工作正常,但是当我用 py2exeservice.py 文件编译为 service.exe 并运行以下命令时:

service.exe install
service.exe start [or trying to restart the service from the Services.msc]

我收到这条消息:

Could not start the  service name service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion

我该如何解决这个问题?

这里还有 distutil 代码:

from distutils.core import setup
import py2exe

py2exe_options = {"includes": ['decimal'],'bundle_files': 1}

setup(console=[{"script":'Service.py'}],
options={"py2exe": py2exe_options},
zipfile = None,
},
)

最佳答案

将您的:setup(console=[{"script":'Service.py'}] 替换为 setup(service=[{"script":'Service.py'} ]. 而不是控制台使用服务。

关于Python win32 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4499859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com