相关疑难解决方法(0)

无法启动用Python编写的Windows服务(win32serviceutil)

我正在尝试启动一个简单的服务示例:

someservice.py:

import win32serviceutil 
import win32service 
import win32event

class SmallestPythonService(win32serviceutil.ServiceFramework):
    _svc_name_ = "SmallestPythonService"
    _svc_display_name_ = "display service"

    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)
Run Code Online (Sandbox Code Playgroud)

我跑的时候

python someservice.py install
Run Code Online (Sandbox Code Playgroud)

一切都很好,服务出现在Windows服务列表中,但是

python someservice.py start
Run Code Online (Sandbox Code Playgroud)

失败,出现"错误1053:服务未及时响应启动或控制请求",但没有任何延迟.

我用谷歌搜索了一个解决方案,它表示pythonservice.exe无法找到时会发生这种情况python27.dll.它实际上不可能,所以我说C:\Python27PATH.现在pythonservice.exe运行正常,但错误1053仍然存在.

我在Windows 7旗舰版上使用pywin32 216运行Python 2.7.2并具有管理员权限.

python windows windows-services pywin32

17
推荐指数
3
解决办法
2万
查看次数

如何创建Celery Windows服务?

我正在尝试创建一个Windows服务来启动Celery.我遇到过一篇使用任务计划程序执行此操作的文章.然而,它似乎推出了许多芹菜实例并且在机器死亡之前不断消耗内存.有没有办法将其作为Windows服务启动?

python windows windows-services celery

10
推荐指数
2
解决办法
9196
查看次数

所有python windows服务无法启动{error 1053}

所有 python代码服务都可以安装但无法启动

Error 1053: The service did not respond to the start or control request in a timely fashion".

因为我的服务可以在我的服务器上安装和启动.我认为我的代码没有问题.

但我仍然想知道是否有一个解决方案,我可以在代码中解决这个错误

我的服务:

import win32serviceutil
import win32service
import win32event

import time
import traceback
import os

import ConfigParser
import time
import traceback
import os
import utils_func
from memcache_synchronizer import *

class MyService(win32serviceutil.ServiceFramework):
    """Windows Service."""
    os.chdir(os.path.dirname(__file__))
    conf_file_name = "memcache_sync_service.ini"
    conf_parser = ConfigParser.SafeConfigParser()
    conf_parser.read(conf_file_name)
    _svc_name_, _svc_display_name_, _svc_description_ = utils_func.get_win_service(conf_parser)

    def __init__(self, args):
        if os.path.dirname(__file__):
            os.chdir(os.path.dirname(__file__))
        win32serviceutil.ServiceFramework.__init__(self, args)

        # create an event that …
Run Code Online (Sandbox Code Playgroud)

python windows-services

7
推荐指数
3
解决办法
8347
查看次数

使用 python 在 Windows 10 上检测 USB 设备插入

我无法获得以下用于检测 USB 设备插入的代码,以便在使用 Python 3.7 的 Windows 10(64 位)计算机上运行。

import win32serviceutil
import win32service
import win32event
import servicemanager

import win32gui
import win32gui_struct
struct = win32gui_struct.struct
pywintypes = win32gui_struct.pywintypes
import win32con

GUID_DEVINTERFACE_USB_DEVICE = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}"
DBT_DEVICEARRIVAL = 0x8000
DBT_DEVICEREMOVECOMPLETE = 0x8004

import ctypes

#
# Cut-down clone of UnpackDEV_BROADCAST from win32gui_struct, to be
# used for monkey-patching said module with correct handling
# of the "name" param of DBT_DEVTYPE_DEVICEINTERFACE
#
def _UnpackDEV_BROADCAST (lparam):
  if lparam == 0: return None
  hdr_format = …
Run Code Online (Sandbox Code Playgroud)

python usb windows-10

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

Python Windows 服务 - 日志记录不起作用

使用 Python 3.7、Windows 10 专业版、Pywin32

我有一个测试脚本,它启动一个服务并在发出不同的命令时将一些基本行推送到日志文件中。代码如下:

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import logging


class AppServerSvc(win32serviceutil.ServiceFramework):
    _svc_name_ = "TestService"
    _svc_display_name_ = "Test Service"
    _svc_description_ = "New Test Service"

    logging.basicConfig(filename='search_server.log', level=logging.INFO)
    logging.info('Class opened')

    def __init__(self, args):
        logging.basicConfig(filename='search_server.log', level=logging.INFO)
        logging.info('Init')
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        socket.setdefaulttimeout(60)


    def SvcStop(self):
        logging.basicConfig(filename='search_server.log', level=logging.INFO)
        logging.info('Stop')
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)


    def SvcDoRun(self):
        logging.basicConfig(filename='search_server.log', level=logging.INFO)
        logging.info('Run')
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_, ''))
        self.main()


    def main(self):
        print("running")
        logging.basicConfig(filename='search_server.log', level=logging.INFO)
        logging.info('Main')


if __name__ == '__main__':
    logging.basicConfig(filename='search_server.log', level=logging.INFO) …
Run Code Online (Sandbox Code Playgroud)

python windows service logging pywin32

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