所有 python windows 服务都无法启动{错误 1053} [英] all python windows service can not start{error 1053}

查看:49
本文介绍了所有 python windows 服务都无法启动{错误 1053}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有python代码服务可以安装但不能启动

all python code service can install but cannot start

错误 1053:服务没有及时响应启动或控制请求".

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

since my service can install and start in my server. i think my code has no problem.

但我仍然想知道是否有解决方案可以解决代码中的此错误

but i still wonder is there a solution that i can solve this error in code

我的服务:

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)

执行sc query [name]"的结果;指令:

execute result of "sc query [name]" cmd:

SERVICE_NAME:NewsMonitoringMemcacheSynchronizer

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

更新:

我可以在调试模式下运行这个服务,cmd:

i can run this service with debug mode, cmd:

memcache_syn_service.py debug

推荐答案

我所有的 Python 编码的 Windows 服务都无法在我的电脑上运行.

all my python coded windows service cannot run on my computer.

但它们都可以在我们的开发服务器上启动,这意味着我的代码是正确的.

but all of them can start at our dev-server which means my code is correct.

但我找到了一个替代解决方案,以调试模式运行:

but i found a alternative solution, run in debug mode:

any_service.py debug

这篇关于所有 python windows 服务都无法启动{错误 1053}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆