小编dan*_*nks的帖子

Windows 的 Python 服务有几个问题

我已经检查了至少几十个与我类似的案例,但仍然没有提出解决方案,我希望有人能解释一下,这里一定有我遗漏的东西。

我正在使用 Python3.6 来创建一个 Windows 服务,如果它没有运行,该服务必须运行一个 .exe 文件。这是.py:

import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import psutil
import subprocess
import os, sys, string, time
import servicemanager


class SLAAgent (win32serviceutil.ServiceFramework):
    _svc_name_ = "SLAAgent"
    _svc_display_name_ = "SLAAgent"

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        socket.setdefaulttimeout(60)
        self.isAlive = True

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

    def SvcDoRun(self):
        self.ReportServiceStatus(win32service.SERVICE_START_PENDING)
        self.ReportServiceStatus(win32service.SERVICE_RUNNING)
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_, ''))
        self._logger.info("Service Is Starting")
        main(self)

    def main(self):
        while self.isAlive:
            rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout) …
Run Code Online (Sandbox Code Playgroud)

python windows service pywin32 pyinstaller

4
推荐指数
1
解决办法
3300
查看次数

标签 统计

pyinstaller ×1

python ×1

pywin32 ×1

service ×1

windows ×1