Python win32 服务 [英] Python win32 service
本文介绍了Python win32 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个最小的 python win32 服务 service.py
没有什么特别的:
I have a minimal python win32 service service.py
that does nothing special:
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
它工作正常,但是当我使用 py2exe
将 service.py
文件编译为 service.exe
并运行以下命令时:
it works fine but when I compile the service.py
file with py2exe
to service.exe
and run the following:
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
我该如何解决这个问题?
How can I resolve this problem?
还有这里的 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,
},
)
推荐答案
Replace your: setup(console=[{"script":'Service.py'}]
with setup(service=[{"script":'Service.py'}]
.使用服务代替控制台.
Replace your: setup(console=[{"script":'Service.py'}]
with setup(service=[{"script":'Service.py'}]
. Instead of console use service.
这篇关于Python win32 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文