[PEAK] terminating PEAK application

Yaroslav Samchuk yarcat at ank-sia.com
Sun Aug 1 08:23:07 EDT 2004


Hello,

I have some problems stopping my application. This application is
working as a Win32 service and our main component is fired like this:

======
def getAppFromConfig(cfgName, scheme=None):
    """Create application components from configuration file
    Parameters:
        cfgName:
            Name of the configuration file.
        scheme:
            Name of the scheme to load. If this argument is None,
            default BBS-server scheme will be used.
            If this argument is not None, it must be given as a file
            URL notation (example: "file:///D|/BBS/app_config.xml").
    """
    if scheme is None:
        scheme = getDefaultScheme()
    cfgName = "file:" + pathname2url(os.path.realpath(cfgName))
    _argv=["ZConfig", scheme, cfgName]
    _argv.extend(sys.argv[1:])
    return commands.ZConfigInterpreter(
        config.makeRoot(),
        argv=_argv,
        componentName="BBS")

class BBSService(win32serviceutil.ServiceFramework):
    ...
    def SvcDoRun(self):
        """Called by SC wrapper if service should be started"""
        import servicemanager
        if len(sys.argv) < 3:
            self.logMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                servicemanager.PYS_SERVICE_STOPPED,
                "No config filename given %r" % sys.argv)
            self.ReportServiceStatus(win32service.SERVICE_STOPPED)
            return
        # creating root object from ini file; executing it
        try:
            _scheme = getDefaultScheme()
            _config = sys.argv[2]
            self.logMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                servicemanager.PYS_SERVICE_STARTED,
                "Config: '%s'\r\nScheme: '%s'" % (_config, _scheme))
            self._root = getAppFromConfig(_config, _scheme)
            _exitCode = self._root.run()
        except Exception, _e:
            self.logException(servicemanager.EVENTLOG_ERROR_TYPE,
                servicemanager.PYS_SERVICE_STOPPED, "%s\r\n\r\n" % _e)
        else:
            if _exitCode:
                _msg = "Exit code %r" % _exitCode
            else:
                _msg = ""
            self.logMsg(
                servicemanager.EVENTLOG_INFORMATION_TYPE,
                servicemanager.PYS_SERVICE_STOPPED, _msg)
        self.ReportServiceStatus(win32service.SERVICE_STOPPED)

    def SvcStop(self):
        """Called by SC wrapper if service should be stopped"""
        stop_BBS()
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
    ...
======

And now I'm trying to implement different kinds of `stop_BBS` routine to
make it work:

======
1) emulating raising of the SIGINT (I didn't find the way to raise
signals under Windows):

def stop_BBS():
    signal.getsignal(signal.SIGINT)(signal.SIGINT, sys._getframe())

---
2) making `eventLoop` global and trying to terminate it:

_mainLoop = None

def stop_BBS():
    _mainLoop.exitWith(0)

class CommandBase(commands.AbstractCommand, ComponentBase):
    mainLoop = binding.Obtain(interfaces.IMainLoop)
    def run(self):
        global _mainLoop
        _mainLoop = self.mainLoop
        self.mainLoop.run()
======

but none of these implementations help me to stop the service :( Could
you, please, tell me, what I'm doing wrong? why application could not be
stopped event if I'm trying to stop mainLoop?

Actually, both of the implementations works, if the program is not
running as a service.


-- 
Best wishes,
Yaroslav



More information about the PEAK mailing list