Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

all python windows service can not start{error 1053}

all python code service can install but cannot start

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

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

my service:

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("
******
memcache_sync_service is running, configuration: %s
******" % (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 
%s" % (traceback.format_exc(),))


if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(MyService)

execute result of "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

update:

i can run this service with debug mode, cmd:

memcache_syn_service.py debug
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Had the same problem using pypiwin32 (version: 220) and python (version: 3.6). I had to copy :

"Python36-32Libsite-packagespypiwin32_system32pywintypes36.dll"

to

"Python36-32Libsite-packageswin32"

for the service to start (was working in debug mode)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...