2012-11-20 81 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

爲我工作。謝謝!但仍然不明白出了什麼問題! –

相關問題