【问题标题】:Python win32 servicePython win32 服务
【发布时间】:2010-12-21 13:42:45
【问题描述】:

我有一个最小的 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,
    },
 )

【问题讨论】:

    标签: python windows-services py2exe winapi


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      试试这个设置:

      py2exe_options = {"includes": ['decimal'],'bundle_files': 1}
      setup(
          service=[{'modules':'Service.py','cmdline_style':'pywin32','description':'your service description'}],
          options={'py2exe':py2exe_options},
          zipfile=None)
      

      【讨论】:

        【解决方案3】:

        一个快速的谷歌想出了这个:http://islascruz.org/html/index.php?gadget=StaticPage&action=Page&id=6

        它有意大利语 cmets,但如果你不懂意大利语,我可以帮你翻译一些东西。

        要真正调试您的问题,我想我们需要查看您的 setup.py distutils 脚本...

        【讨论】:

          【解决方案4】:

          您可能缺少正确的路径来查找服务所需的所有 DLL。通常该服务作为“LocalSystem”服务安装,因此您需要将 PATH 添加到系统(而不是用户)。

          尝试将 c:\python27(或任何 python dll 的路径)添加到 SYSTEM PATH,重新启动计算机并检查它现在是否可以正常启动。

          【讨论】:

            猜你喜欢
            • 2010-09-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-10-24
            • 2014-10-26
            相关资源
            最近更新 更多