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

Sco*_*合理论 7 python windows-services

所有 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 SvcDoRun can wait on and SvcStop can set.
        self.stop_event = win32event.CreateEvent(None, 0, 0, None)

    def SvcDoRun(self):
        self.Run()
        win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.stop_event)
        LoggerInstance.log("memcache_sync service is stopped")
        self.ReportServiceStatus(win32service.SERVICE_STOPPED)
        sys.exit()

    def Run(self):
        try:
            LoggerInstance.log("\n******\n\memcache_sync_service is running, configuration: %s\n******" % (self.conf_file_name,))
            if ((not self.conf_parser.has_section('Memcache')) or
                (not self.conf_parser.has_option('Memcache', 'check_interval'))):
                LoggerInstance.log('memcache_sync_service : no Memcache service parameters')
                self.SvcStop()

            # set configuration parameters from ini configuration
            self.check_interval = self.conf_parser.getint('Memcache', 'check_interval')

            ms = MemcacheSynchronizer()
            while 1:
                ms.Sync()
                time.sleep(self.check_interval)
        except:
            LoggerInstance.log("Unhandled Exception \n\t%s" % (traceback.format_exc(),))


if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(MyService)
Run Code Online (Sandbox Code Playgroud)

执行"sc query [name]"cmd的结果:

SERVICE_NAME:NewsMonitoringMemcacheSynchronizer

   TYPE               : 10  WIN32_OWN_PROCESS 
   STATE              : 1  STOPPED 
                           (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
   WIN32_EXIT_CODE    : 0 (0x0)
   SERVICE_EXIT_CODE  : 0 (0x0)
   CHECKPOINT         : 0x0
   WAIT_HINT          : 0x0
Run Code Online (Sandbox Code Playgroud)

更新:

我可以使用调试模式cmd运行此服务:

memcache_syn_service.py debug
Run Code Online (Sandbox Code Playgroud)

小智 9

使用pypiwin32(版本:220)和python(版本:3.6)有同样的问题.我不得不将"\ Python36-32\Lib\site-packages\pypiwin32_system32\pywintypes36.dll"复制到"\ Python36-32\Lib\site-packages\win32"以启动服务(在调试模式下工作)


fla*_*am3 7

如果:

  • python your_service.py debug 工作,而
  • python your_service.py install +将其启动为服务失败并出现错误1053,

该命令可能会有所帮助python C:\Python27\Scripts\pywin32_postinstall.py

  • `python C:\Python27\Scripts\pywin32_postinstall.py -install` 对我有用,谢谢! (3认同)

Sco*_*合理论 5

我的所有python编码的Windows服务都无法在我的计算机上运行.

但是所有这些都可以从我们的开发服务器开始,这意味着我的代码是正确的.

但我找到了另一种解决方案,运行于debug mode:

any_service.py debug
Run Code Online (Sandbox Code Playgroud)