Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::Core::signalHandler (   signum,
  frame 
)

The main and only signal handler. Handle cleanup/managing child processes before
exiting 

Definition at line 146 of file Core.py.

00146                                 :
    """ The main and only signal handler. Handle cleanup/managing child processes before
    exiting """
    # CTRL-C
    if signum == signal.SIGINT:
        # If there aren't any proceses to wait for exit immediately
        if len(Topen.activePool) == 0:
            shutdown(message = 'Caught interrupt, exiting..')
            return

        # We can safely exit ASAP if all the processes are associated with the main thread
        # (the thread processes? seem to have have already gotten the signal as well at
        # this point. I'm not exactly sure why)
        threadsOutsideMain = False
        for topen in Topen.activePool:
            if topen.threadIdent != Hellanzb.MAIN_THREAD_IDENT:
                threadsOutsideMain = True

        if not threadsOutsideMain:
            shutdown(message = 'Caught interrupt, exiting..')
            return

        # We couldn't cheat our way out of the program, tell the user the processes
        # (threads) we're waiting on, and wait for another signal
        if Hellanzb.stopSignalCount == 0 or (time.time() - Hellanzb.firstSignal > 5):
            Hellanzb.firstSignal = time.time()
            Hellanzb.stopSignalCount = 1
        else:
            Hellanzb.stopSignalCount = Hellanzb.stopSignalCount + 1

        if Hellanzb.stopSignalCount < 2:
            msg = 'Caught interrupt, waiting for these child processes to finish:\n'
            for topen in Topen.activePool:
                pid = topen.getPid()
                if pid is None:
                    pid = 'Init'
                else:
                    pid = str(pid)
                msg += truncateToMultiLine(topen.prettyCmd, length = 68,
                                           prefix = pid + '  ', indentPrefix = ' '*8) + '\n'
            msg += '(CTRL-C again within 5 seconds to kill them and exit immediately.\n' + \
                'PostProcessors will automatically resume when hellanzb is restarted)'
            warn(msg)
            
        else:
            # Kill the processes. If any processes are lying around after a kill -9, it's
            # either an o/s problem (we don't care) or a bug in hellanzb (we aren't
            # allowing the process to exit/still reading from it)
            warn('Killing child processes..')
            shutdown(message = 'Killed all child processes, exiting..',
                     killPostProcessors = True)
            return
            
def init(options = {}):


Generated by  Doxygen 1.6.0   Back to index