Exemple #1
0
def shutdown():
    from logs import lg
    from main import config
    from system import bpio
    if _Debug:
        lg.out(_DebugLevel, 'bpmain.shutdown')

    if config.conf():
        config.conf().removeConfigNotifier('logs/debug-level')

    from main import shutdowner
    shutdowner.A('reactor-stopped')

    from main import listeners
    listeners.shutdown()

    from main import events
    events.shutdown()

    from automats import automat
    automat.objects().clear()
    if len(automat.index()) > 0:
        lg.warn('%d automats was not cleaned' % len(automat.index()))
        for a in automat.index().keys():
            if _Debug:
                lg.out(_DebugLevel, '    %r' % a)
    else:
        if _Debug:
            lg.out(
                _DebugLevel,
                'bpmain.shutdown automat.objects().clear() SUCCESS, no state machines left in memory'
            )

    if _Debug:
        lg.out(
            _DebugLevel, 'bpmain.shutdown currently %d threads running:' %
            len(threading.enumerate()))
    for t in threading.enumerate():
        if _Debug:
            lg.out(_DebugLevel, '    ' + str(t))

    if _Debug:
        lg.out(_DebugLevel,
               'bpmain.shutdown finishing and closing log file, EXIT')

    # automat.CloseLogFile()
    automat.SetExceptionsHandler(None)
    automat.SetLogOutputHandler(None)

    lg.close_log_file()

    lg.close_intercepted_log_file()

    lg.stdout_stop_redirecting()
    lg.stderr_stop_redirecting()

    from main import settings
    settings.shutdown()

    return 0
Exemple #2
0
def shutdown():
    from logs import lg
    from main import config
    from system import bpio
    lg.out(2, 'bpmain.shutdown')

    from . import shutdowner
    shutdowner.A('reactor-stopped')

    from main import events
    events.shutdown()

    from automats import automat
    automat.objects().clear()
    if len(automat.index()) > 0:
        lg.warn('%d automats was not cleaned' % len(automat.index()))
        for a in automat.index().keys():
            lg.out(2, '    %r' % a)
    else:
        lg.out(
            2,
            'bpmain.shutdown automat.objects().clear() SUCCESS, no state machines left in memory'
        )

    config.conf().removeCallback('logs/debug-level')

    lg.out(
        2, 'bpmain.shutdown currently %d threads running:' %
        len(threading.enumerate()))
    for t in threading.enumerate():
        lg.out(2, '    ' + str(t))

    lg.out(2, 'bpmain.shutdown finishing and closing log file, EXIT')

    automat.CloseLogFile()

    lg.close_log_file()

    if bpio.Windows() and bpio.isFrozen():
        lg.stdout_stop_redirecting()

    return 0
Exemple #3
0
def shutdown(x=None):
    """
    This is a top level method which control the process of finishing the
    program.

    Calls method ``shutdown()`` in other modules.
    """
    if _Debug:
        lg.out(_DebugLevel, "shutdowner.shutdown " + str(x))
    dl = []
    try:
        from services import driver
        from main import control
        from main import events
        from main import listeners
        from logs import weblog
        from logs import webtraffic
        from system import tmpfile
        from system import run_upnpc
        from raid import eccmap
        from lib import net_misc
        from updates import git_proc
        from interface import api_rest_http_server
        from interface import api_web_socket
        # from interface import ftp_server
        from contacts import identitydb
        from crypt import my_keys
        from userid import id_url
        from userid import my_id
        my_keys.shutdown()
        my_id.shutdown()
        identitydb.shutdown()
        # ftp_server.shutdown()
        api_rest_http_server.shutdown()
        api_web_socket.shutdown()
        driver.shutdown()
        eccmap.shutdown()
        run_upnpc.shutdown()
        net_misc.shutdown()
        git_proc.shutdown()
        listeners.shutdown()
        events.shutdown()
        tmpfile.shutdown()
        control.shutdown()
        try:
            weblog.shutdown()
        except:
            lg.exc()
        try:
            webtraffic.shutdown()
        except:
            lg.exc()
        survived_automats = list(automat.objects().values())
        if survived_automats:
            lg.warn(
                'found %d survived state machines, sending "shutdown" event to them all'
                % len(survived_automats))
            for a in survived_automats:
                if a.name != 'shutdowner':
                    a.event('shutdown')
        survived_automats = list(automat.objects().values())
        if survived_automats:
            lg.warn(
                'still found %d survived state machines, executing "destroy()" method to them all'
                % len(survived_automats))
            for a in survived_automats:
                if a.name != 'shutdowner':
                    a.destroy()
        settings.shutdown()
        id_url.shutdown()
    except:
        lg.exc()
    # TODO: rework all shutdown() methods to return deferred objects
    return DeferredList(dl)