加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python win32服务

发布时间:2020-12-20 11:16:22 所属栏目:Python 来源:网络整理
导读:我有一个最小的 python win32服务service.py没有什么特别的: import win32serviceutilimport win32serviceimport win32eventclass SmallestPythonService(win32serviceutil.ServiceFramework): _svc_name_ = "SmallestPythonService" _svc_display_name_ =
我有一个最小的 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,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并运行以下代码时:

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(service = [{“script”:’Service.py’}]替换你的:setup(console = [{“script”:’Service.py’}].而不是控制台使用服务.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读