Python logging.shutdown() Examples

The following are 30 code examples of logging.shutdown(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module logging , or try the search function .
Example #1
Source File: start.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def signal_handler(signal, frame=None):
    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    core_singletons.shut_down_signal = signal

    # in this case the print is on purpose to see more easily if the interrupt signal reached the thread
    print(_("Signal '{}' received.\nExecution engine will be stopped and program will be shutdown!").format(
        SIGNALS_TO_NAMES_DICT.get(signal, "[unknown]")))

    # close gui properly
    gui_singletons.main_window_controller.get_controller('menu_bar_controller').on_quit_activate(None)

    post_gui_destruction()

    logging.shutdown()

    # Do not use sys.exit() in signal handler:
    # http://thushw.blogspot.de/2010/12/python-dont-use-sysexit-inside-signal.html
    # noinspection PyProtectedMember
    os._exit(0) 
Example #2
Source File: start.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def register_signal_handlers(callback):
    # When using plain signal.signal to install a signal handler, the GUI will not shutdown until it receives the
    # focus again. The following logic (inspired from https://stackoverflow.com/a/26457317) fixes this
    def install_glib_handler(sig):
        unix_signal_add = None

        if hasattr(GLib, "unix_signal_add"):
            unix_signal_add = GLib.unix_signal_add
        elif hasattr(GLib, "unix_signal_add_full"):
            unix_signal_add = GLib.unix_signal_add_full

        if unix_signal_add:
            unix_signal_add(GLib.PRIORITY_HIGH, sig, callback, sig)

    def idle_handler(*args):
        GLib.idle_add(callback, *args, priority=GLib.PRIORITY_HIGH)

    for signal_code in [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]:
        signal.signal(signal_code, idle_handler)
        GLib.idle_add(install_glib_handler, signal_code, priority=GLib.PRIORITY_HIGH) 
Example #3
Source File: log_helpers.py    From n6 with GNU Affero General Public License v3.0 6 votes vote down vote up
def close(self):
        # typically, this method is called at interpreter exit
        # (by logging.shutdown() which is always registered with
        # atexit.register() machinery)
        try:
            try:
                super(AMQPHandler, self).close()
                self._closing = True
                self._pusher.shutdown()
            except:
                dump_condensed_debug_msg(
                    'EXCEPTION DURING EXECUTION OF close() OF THE AMQP LOGGING HANDLER!')
                raise
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            exc = sys.exc_info()[1]
            self._error_fifo.put(exc) 
Example #4
Source File: start.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def signal_handler(signal, frame):
    global _user_abort

    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    core_singletons.shut_down_signal = signal

    logger.info("Shutting down ...")

    try:
        if not state_machine_execution_engine.finished_or_stopped():
            state_machine_execution_engine.stop()
            state_machine_execution_engine.join(3)  # Wait max 3 sec for the execution to stop
    except Exception:
        logger.exception("Could not stop state machine")

    _user_abort = True

    # shutdown twisted correctly
    if reactor_required():
        from twisted.internet import reactor
        if reactor.running:
            plugins.run_hook("pre_destruction")
            reactor.callFromThread(reactor.stop)

    logging.shutdown() 
Example #5
Source File: logging.py    From python-netsurv with MIT License 6 votes vote down vote up
def pytest_sessionfinish(self):
        with self.live_logs_context():
            if self.log_cli_handler:
                self.log_cli_handler.set_when("sessionfinish")
            if self.log_file_handler is not None:
                try:
                    with catching_logs(
                        self.log_file_handler, level=self.log_file_level
                    ):
                        yield
                finally:
                    # Close the FileHandler explicitly.
                    # (logging.shutdown might have lost the weakref?!)
                    self.log_file_handler.close()
            else:
                yield 
Example #6
Source File: logging.py    From python-netsurv with MIT License 6 votes vote down vote up
def pytest_sessionfinish(self):
        with self.live_logs_context():
            if self.log_cli_handler:
                self.log_cli_handler.set_when("sessionfinish")
            if self.log_file_handler is not None:
                try:
                    with catching_logs(
                        self.log_file_handler, level=self.log_file_level
                    ):
                        yield
                finally:
                    # Close the FileHandler explicitly.
                    # (logging.shutdown might have lost the weakref?!)
                    self.log_file_handler.close()
            else:
                yield 
Example #7
Source File: test_logging_config.py    From airflow with Apache License 2.0 6 votes vote down vote up
def reset_logging():
    """Reset Logging"""
    manager = logging.root.manager
    manager.disabled = logging.NOTSET
    airflow_loggers = [
        logger for logger_name, logger in manager.loggerDict.items() if logger_name.startswith('airflow')
    ]
    for logger in airflow_loggers:  # pylint: disable=too-many-nested-blocks
        if isinstance(logger, logging.Logger):
            logger.setLevel(logging.NOTSET)
            logger.propagate = True
            logger.disabled = False
            logger.filters.clear()
            handlers = logger.handlers.copy()
            for handler in handlers:
                # Copied from `logging.shutdown`.
                try:
                    handler.acquire()
                    handler.flush()
                    handler.close()
                except (OSError, ValueError):
                    pass
                finally:
                    handler.release()
                logger.removeHandler(handler) 
Example #8
Source File: main.py    From security-utilities with GNU General Public License v3.0 6 votes vote down vote up
def main(args):
    """ Main

    TODO: validate ip address input
    
    """
    setup_logs()
    _logger.debug("Starting main()")

    ips = []
    args = parse_args(args)
    print("[*] Fuzzing port {} on IP address {}".format(args.port, args.ip))
    fuzz(args.ip, args.port, args.size, args.increment)

    _logger.debug("All done, shutting down.")
    logging.shutdown() 
Example #9
Source File: main.py    From security-utilities with GNU General Public License v3.0 6 votes vote down vote up
def main(args):
    """ Main

    """
    setup_logs()
    _logger.debug("Starting main()")

    args = parse_args(args)
    print("[*] Initiating attack on IP address {}:{}".format(args.ip, args.port))
    if args.test:
        pwn(args.ip, args.port, 'test')
    elif args.unique:
        pwn(args.ip, args.port, 'unique')
    elif args.chars:
        pwn(args.ip, args.port, 'chars')
    elif args.breakpoint:
        pwn(args.ip, args.port, 'break')
    else:
        pwn(args.ip, args.port, args.payload)

    _logger.debug("All done, shutting down.")
    logging.shutdown() 
Example #10
Source File: cd_plug_lib.py    From CudaText with Mozilla Public License 2.0 5 votes vote down vote up
def __del__(self):
        logging.shutdown() 
Example #11
Source File: transcoder.py    From tested-transcoder with MIT License 5 votes vote down vote up
def stop(self):
        # guard against multiple signals being sent before the first one
        # finishes
        if not self.running:
            return
        self.running = False
        self.logger.info('Transcoder shutting down')
        if self.current_command:
            self.current_command.terminate()
        # logging
        logging.shutdown()
        self.logger = None
        # signal handlers
        self.restore_signal_handlers() 
Example #12
Source File: test_logging.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def stop(self, timeout=None):
            """
            Tell the server thread to stop, and wait for it to do so.

            :param timeout: How long to wait for the server thread
                            to terminate.
            """
            self.shutdown()
            if self._thread is not None:
                self._thread.join(timeout)
                self._thread = None
            self.server_close()
            self.ready.clear() 
Example #13
Source File: test_logging.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_no_failure(self):
        # create some fake handlers
        handler0 = FakeHandler(0, self.called)
        handler1 = FakeHandler(1, self.called)
        handler2 = FakeHandler(2, self.called)

        # create live weakref to those handlers
        handlers = map(logging.weakref.ref, [handler0, handler1, handler2])

        logging.shutdown(handlerList=list(handlers))

        expected = ['2 - acquire', '2 - flush', '2 - close', '2 - release',
                    '1 - acquire', '1 - flush', '1 - close', '1 - release',
                    '0 - acquire', '0 - flush', '0 - close', '0 - release']
        self.assertEqual(expected, self.called) 
Example #14
Source File: cd_plug_lib.py    From CudaText with Mozilla Public License 2.0 5 votes vote down vote up
def __del__(self):
        logging.shutdown() 
Example #15
Source File: pingsweep.py    From security-utilities with GNU General Public License v3.0 5 votes vote down vote up
def main(args):
    """ Main

    TODO: validate ip address input
    
    """
    setup_logs()
    _logger.debug("Starting main()")

    ips = []
    args = parse_args(args)
    print("[*] Scanning IP addresses: {}".format(args.ips))
    if args.a:
        ips = get_addresses('a', args.ips)
        if args.ICMP:
            icmp_sweeper(ips, args.threads, 'ICMP')
        elif args.SMTP:
            smtp_sweeper(ips, args.threads, 'SMTP')
    elif args.b:
        ips = get_addresses('b', args.ips)
        if args.ICMP:
            icmp_sweeper(ips, args.threads, 'ICMP')
        elif args.SMTP:
            smtp_sweeper(ips, args.threads, 'SMTP')
    elif args.c:
        ips = get_addresses('c', args.ips)
        if args.ICMP:
            sweeper(ips, args.threads, 'ICMP')
        elif args.SMTP:
            sweeper(ips, args.threads, 'SMTP')
    else:
        if args.ICMP:
            sweeper(args.ips, args.threads, 'ICMP')
        elif args.SMTP:
            sweeper(args.ips, args.threads, 'SMTP')

    _logger.debug("All done, shutting down.")
    logging.shutdown() 
Example #16
Source File: cd_plug_lib.py    From CudaText with Mozilla Public License 2.0 5 votes vote down vote up
def __del__(self):
        logging.shutdown() 
Example #17
Source File: needl.py    From Needl with MIT License 5 votes vote down vote up
def stop():
    needl.log.warn('Shutting down')

    scheduler.stop()

    if needl.args.logfile is not sys.stdout:
        needl.log.debug('Closing logfile %s', needl.args.logfile.name)
        needl.args.logfile.close()

    logging.shutdown()
    sys.exit() 
Example #18
Source File: cd_plug_lib.py    From CudaText with Mozilla Public License 2.0 5 votes vote down vote up
def __del__(self):
        logging.shutdown() 
Example #19
Source File: HXTool.py    From Hyperflex-Hypercheck with MIT License 5 votes vote down vote up
def log_stop():
    # Shutdown the logger handler
    #log_msg(INFO, "Shutdown the logger")
    logging.shutdown() 
Example #20
Source File: transcoder.py    From tested-transcoder with MIT License 5 votes vote down vote up
def setup_signal_handlers(self):
        "Setup graceful shutdown and cleanup when sent a signal"
        def handler(signum, frame):
            self.stop()

        for sig in (signal.SIGTERM, signal.SIGHUP, signal.SIGINT):
            self._default_handlers[sig] = signal.signal(sig, handler) 
Example #21
Source File: process_test.py    From honeything with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        if task_id() is not None:
            # We're in a child process, and probably got to this point
            # via an uncaught exception.  If we return now, both
            # processes will continue with the rest of the test suite.
            # Exit now so the parent process will restart the child
            # (since we don't have a clean way to signal failure to
            # the parent that won't restart)
            logging.error("aborting child process from tearDown")
            logging.shutdown()
            os._exit(1)
        # In the surviving process, clear the alarm we set earlier
        signal.alarm(0)
        super(ProcessTest, self).tearDown() 
Example #22
Source File: config.py    From Imogen with MIT License 5 votes vote down vote up
def _clearExistingHandlers():
    """Clear and close existing handlers"""
    logging._handlers.clear()
    logging.shutdown(logging._handlerList[:])
    del logging._handlerList[:] 
Example #23
Source File: process_test.py    From pySINDy with MIT License 5 votes vote down vote up
def tearDown(self):
        if task_id() is not None:
            # We're in a child process, and probably got to this point
            # via an uncaught exception.  If we return now, both
            # processes will continue with the rest of the test suite.
            # Exit now so the parent process will restart the child
            # (since we don't have a clean way to signal failure to
            # the parent that won't restart)
            logging.error("aborting child process from tearDown")
            logging.shutdown()
            os._exit(1)
        # In the surviving process, clear the alarm we set earlier
        signal.alarm(0)
        super(ProcessTest, self).tearDown() 
Example #24
Source File: test_logging.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(LoggerAdapterTest, self).setUp()
        old_handler_list = logging._handlerList[:]

        self.recording = RecordingHandler()
        self.logger = logging.root
        self.logger.addHandler(self.recording)
        self.addCleanup(self.logger.removeHandler, self.recording)
        self.addCleanup(self.recording.close)

        def cleanup():
            logging._handlerList[:] = old_handler_list

        self.addCleanup(cleanup)
        self.addCleanup(logging.shutdown)
        self.adapter = logging.LoggerAdapter(logger=self.logger, extra=None) 
Example #25
Source File: test_logging.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super(LoggerTest, self).setUp()
        self.recording = RecordingHandler()
        self.logger = logging.Logger(name='blah')
        self.logger.addHandler(self.recording)
        self.addCleanup(self.logger.removeHandler, self.recording)
        self.addCleanup(self.recording.close)
        self.addCleanup(logging.shutdown) 
Example #26
Source File: test_logging.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super(LoggerAdapterTest, self).setUp()
        old_handler_list = logging._handlerList[:]

        self.recording = RecordingHandler()
        self.logger = logging.root
        self.logger.addHandler(self.recording)
        self.addCleanup(self.logger.removeHandler, self.recording)
        self.addCleanup(self.recording.close)

        def cleanup():
            logging._handlerList[:] = old_handler_list

        self.addCleanup(cleanup)
        self.addCleanup(logging.shutdown)
        self.adapter = logging.LoggerAdapter(logger=self.logger, extra=None) 
Example #27
Source File: test_logging.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def _test_with_failure_in_method(self, method, error):
        handler = FakeHandler(0, self.called)
        setattr(handler, method, self.raise_error(error))
        handlers = [logging.weakref.ref(handler)]

        logging.shutdown(handlerList=list(handlers))

        self.assertEqual('0 - release', self.called[-1]) 
Example #28
Source File: test_logging.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_no_failure(self):
        # create some fake handlers
        handler0 = FakeHandler(0, self.called)
        handler1 = FakeHandler(1, self.called)
        handler2 = FakeHandler(2, self.called)

        # create live weakref to those handlers
        handlers = map(logging.weakref.ref, [handler0, handler1, handler2])

        logging.shutdown(handlerList=list(handlers))

        expected = ['2 - acquire', '2 - flush', '2 - close', '2 - release',
                    '1 - acquire', '1 - flush', '1 - close', '1 - release',
                    '0 - acquire', '0 - flush', '0 - close', '0 - release']
        self.assertEqual(expected, self.called) 
Example #29
Source File: test_logging.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def stop(self, timeout=None):
            """
            Tell the server thread to stop, and wait for it to do so.

            :param timeout: How long to wait for the server thread
                            to terminate.
            """
            self.shutdown()
            if self._thread is not None:
                self._thread.join(timeout)
                self._thread = None
            self.server_close()
            self.ready.clear() 
Example #30
Source File: start.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def stop_gtk():
    # shutdown twisted correctly
    if reactor_required():
        from twisted.internet import reactor
        if reactor.running:
            reactor.callFromThread(reactor.stop)
        # Twisted can be imported without the reactor being used
        # => check if GTK main loop is running
        elif Gtk.main_level() > 0:
            GLib.idle_add(Gtk.main_quit)
    else:
        GLib.idle_add(Gtk.main_quit)

    # Run the GTK loop until no more events are being generated and thus the GUI is fully destroyed
    wait_for_gui()