2012-11-20 82 views
2

所有 Python代码服务可以安装,但无法启动所有的Python窗口服务无法启动{错误1053}

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) 

执行的 “SC查询[名]” 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 

更新:

我可以运行与调试模式,CMD此服务:

memcache_syn_service.py debug 
+0

This [answer](https://stackoverflow.com/questions/10556689/error-1053-when-starting-window-service-written-in-python)建议将Python添加到系统PATH中。那对我有效 –

回答

5

我所有的Python编写的Windows服务不能在我的电脑上运行。

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

,但我发现了一个替代的解决方案,在debug mode运行:

any_service.py debug 
+0

def Run(self):可以像打印“测试”一行吗?或者所有这些垃圾代码都必须在那里? – YumYumYum

1

我有类似的问题,蟒蛇服务,并发现它缺少DLL文件,因为“系统路径”(而不是用户路径)不完整。检查开发服务器中的路径以及它是否与计算机上的路径相匹配(如果服务作为LocalSystem服务安装,则为系统路径)。对我而言,我缺少python dll的路径c:\ python27(windows)。

+0

这为我工作。虽然这将有助于知道什么是缺少的,以及它是否可以包含在使用pyinstaller制作可执行文件时 – Ubica

4

使用pypiwin32(版本:220)和python(版本:3.6)有同样的问题。我必须将“\ Python36-32 \ Lib \ site-packages \ pypiwin32_system32 \ pywintypes36.dll”复制到“\ Python36-32 \ Lib \ site-packages \ win32”,才能启动服务(正在调试模式下工作)

+1

为我工作。谢谢!但仍然不明白出了什么问题! –

相关问题