当我尝试调试我的服务时:
D:\SEngine>alert_historycal_news_service.py debug
Debugging service NMS- press Ctrl+C to stop.
Debugging service NMs - press Ctrl+C to stop.
Error 0xC00000F4 - Could not find the service's PythonClass entry in the registry
Error 1814 - The specified resource name cannot be found in the image file.
Error 0xC0000080 - Could not locate the module name in the Python class string (ie, no '.')
这是我的代码:
"""
The basic Windows service for News Alert Engine
"""
import win32serviceutil
import win32service
import win32event
import time
import os
import ConfigParser
import traceback
from utils_func import *
from utils_db import *
from log import *
from news_alert.alert_engine_metadata import *
from news_alert.alert_engine_missing import *
class MyAlertService(win32serviceutil.ServiceFramework):
"""Windows Service."""
os.chdir(os.path.dirname(__file__))
conf_file_name = "alert_historycal_news_service.ini"
conf_parser = ConfigParser.SafeConfigParser()
conf_parser.read(conf_file_name)
_svc_name_, _svc_display_name_, _svc_description_ = 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)
self.root_logger = get_logger(MyAlertService._svc_name_)
# 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)
self.root_logger.info("service stopped")
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
sys.exit()
def Run(self):
try:
self.root_logger.info("alert_news_missing service is running, configuration: %s" % (self.conf_file_name,))
if ((not self.conf_parser.has_section('NewsMissing')) or
(not self.conf_parser.has_option('NewsMissing', 'check_interval')) or
(not self.conf_parser.has_option('NewsMissing', 'running_time'))):
self.root_logger.warning("no NewsMissing service parameters")
self.SvcStop()
# set configuration parameters from ini configuration
self.check_interval = self.conf_parser.getint('NewsMissing', 'check_interval')
running_time = self.conf_parser.get('NewsMissing', 'running_time')
self.root_logger.info('service start running, time: %s' % running_time)
check_time = time.strptime(running_time, "%H %M")
while 1:
curr_time = time.gmtime()
if curr_time.tm_hour == check_time.tm_hour and curr_time.tm_min == check_time.tm_min:
p = NewsMissingChecker(self.conf_parser)
p.Apply_Rules()
metadataChecker = NewsMetadataChecker(self.conf_parser)
metadataChecker.Analyse()
time.sleep(self.check_interval)
except:
self.root_logger.critical("service crashed!")
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyAlertService)