Python signal 模块,SIGABRT 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用signal.SIGABRT

项目:mobot    作者:JokerQyou    | 项目源码 | 文件源码
def idle(self, stop_signals=(SIGINT, SIGTERM, SIGABRT)):
        """
        Blocks until one of the signals are received and stops the updater

        Args:
            stop_signals: Iterable containing signals from the signal module
                that should be subscribed to. Updater.stop() will be called on
                receiving one of those signals. Defaults to (SIGINT, SIGTERM,
                SIGABRT)
        """
        for sig in stop_signals:
            signal(sig, self.signal_handler)

        self.is_idle = True

        while self.is_idle:
            sleep(1)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:uvicorn    作者:encode    | 项目源码 | 文件源码
def run(self, app, host, port):
        asyncio.get_event_loop().close()
        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

        loop = asyncio.get_event_loop()

        loop.add_signal_handler(signal.SIGQUIT, self.handle_exit, signal.SIGQUIT, None)
        loop.add_signal_handler(signal.SIGTERM, self.handle_exit, signal.SIGTERM, None)
        loop.add_signal_handler(signal.SIGINT, self.handle_exit, signal.SIGINT, None)
        loop.add_signal_handler(signal.SIGABRT, self.handle_exit, signal.SIGABRT, None)

        loop.create_task(self.create_server(loop, app, host, port))
        loop.create_task(self.tick(loop))

        logger.warning('Starting worker [{}] serving at: {}:{}'.format(os.getpid(), host, port))

        loop.run_forever()
项目:freqtrade    作者:gcarq    | 项目源码 | 文件源码
def init(config: dict, db_url: Optional[str] = None) -> None:
    """
    Initializes all modules and updates the config
    :param config: config as dict
    :param db_url: database connector string for sqlalchemy (Optional)
    :return: None
    """
    # Initialize all modules
    rpc.init(config)
    persistence.init(config, db_url)
    exchange.init(config)

    # Set initial application state
    initial_state = config.get('initial_state')
    if initial_state:
        update_state(State[initial_state.upper()])
    else:
        update_state(State.STOPPED)

    # Register signal handlers
    for sig in (SIGINT, SIGTERM, SIGABRT):
        signal(sig, cleanup)
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_memory_local_killer(self):
        local_killer = devices.killer.LocalKiller(
            pid=os.getpid(),
            soft_timeout=0.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=0.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=0.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        local_killer.start()
        self.sigint_fired = False
        self.assertFalse(self.sigint_fired)
        mem_buffer = ' ' * (3 * 1024 * 1024 * 1024)
        time.sleep(1)
        self.assertFalse(self.sigint_fired)
        mem_buffer += ' ' * (1 * 1024 * 1024 * 1024)
        time.sleep(1)
        self.assertTrue(self.sigint_fired)
        local_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_memory_remote_killer(self):
        local_killer = devices.killer.RemoteKiller(
            pid=os.getpid(),
            soft_timeout=0.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=0.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=0.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        local_killer.start()
        self.sigint_fired = False
        self.assertFalse(self.sigint_fired)
        mem_buffer = ' ' * (3 * 1024 * 1024 * 1024)
        time.sleep(1)
        self.assertFalse(self.sigint_fired)
        mem_buffer += ' ' * (1 * 1024 * 1024 * 1024)
        time.sleep(1)
        self.assertTrue(self.sigint_fired)
        local_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def begin_working(
        self,
    ):
        if self.worker_config['timeouts']['critical_timeout'] == 0:
            killer_device = devices.killer.LocalKiller
        else:
            killer_device = devices.killer.RemoteKiller

        self.killer = killer_device(
            pid=os.getpid(),
            soft_timeout=self.worker_config['timeouts']['soft_timeout'],
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=self.worker_config['timeouts']['hard_timeout'],
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=self.worker_config['timeouts']['critical_timeout'],
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=self.worker_config['limits']['memory'],
            memory_limit_signal=signal.SIGABRT,
        )

        signal.signal(signal.SIGABRT, self.sigabrt_handler)
        signal.signal(signal.SIGINT, self.sigint_handler)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:Price-Comparator    作者:Thejas-1    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:OpenDoor    作者:stanislav-web    | 项目源码 | 文件源码
def termination_handler():
        """
        Exit Ctrl-Z handler
        :return: None
        """

        def kill_process(signum, frame):
            """
            Kill process os signal
            :param int signum: signal code
            :param object frame: frame object
            :return: None
            """

            del signum
            del frame

            os.kill(os.getpid(), signal.SIGTERM)

        sig = getattr(signal, 'SIGTSTP', signal.SIGABRT)
        signal.signal(sig, kill_process)
项目:sanic    作者:channelcat    | 项目源码 | 文件源码
def init_signals(self):
        # Set up signals through the event loop API.

        self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
                                     signal.SIGQUIT, None)

        self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
                                     signal.SIGTERM, None)

        self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
                                     signal.SIGINT, None)

        self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
                                     signal.SIGWINCH, None)

        self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
                                     signal.SIGUSR1, None)

        self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
                                     signal.SIGABRT, None)

        # Don't let SIGTERM and SIGUSR1 disturb active requests
        # by interrupting system calls
        signal.siginterrupt(signal.SIGTERM, False)
        signal.siginterrupt(signal.SIGUSR1, False)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_issue9324(self):
        # Updated for issue #10003, adding SIGBREAK
        handler = lambda x, y: None
        checked = set()
        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
                    signal.SIGTERM):
            # Set and then reset a handler for signals that work on windows.
            # Issue #18396, only for signals without a C-level handler.
            if signal.getsignal(sig) is not None:
                signal.signal(sig, signal.signal(sig, handler))
                checked.add(sig)
        # Issue #18396: Ensure the above loop at least tested *something*
        self.assertTrue(checked)

        with self.assertRaises(ValueError):
            signal.signal(-1, handler)

        with self.assertRaises(ValueError):
            signal.signal(7, handler)
项目:infiblog    作者:RajuKoushik    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:py_daemoniker    作者:Muterra    | 项目源码 | 文件源码
def _default_handler(signum, *args):
        ''' The default signal handler for Unix.
        '''
        # Just parallel the sighandlers that are available in Windows, because
        # it is definitely the limiting factor here
        sigs = {
            signal.SIGABRT: SIGABRT,
            signal.SIGINT: SIGINT,
            signal.SIGTERM: SIGTERM,
        }

        try:
            exc = sigs[signum]
        except KeyError:
            exc = DaemonikerSignal

        raise exc()
项目:py_daemoniker    作者:Muterra    | 项目源码 | 文件源码
def _default_handler(signum, *args):
        ''' The default signal handler. Don't register with built-in
        signal.signal! This needs to be used on the subprocess await
        death workaround.
        '''
        # All valid cpython windows signals
        sigs = {
            signal.SIGABRT: SIGABRT,
            # signal.SIGFPE: 'fpe', # Don't catch this
            # signal.SIGSEGV: 'segv', # Don't catch this
            # signal.SIGILL: 'illegal', # Don't catch this
            signal.SIGINT: SIGINT,
            signal.SIGTERM: SIGTERM,
            # Note that signal.CTRL_C_EVENT and signal.CTRL_BREAK_EVENT are
            # converted to SIGINT in _await_signal
        }

        try:
            exc = sigs[signum]
        except KeyError:
            exc = DaemonikerSignal

        _sketch_raise_in_main(exc)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_issue9324(self):
        # Updated for issue #10003, adding SIGBREAK
        handler = lambda x, y: None
        checked = set()
        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
                    signal.SIGTERM):
            # Set and then reset a handler for signals that work on windows.
            # Issue #18396, only for signals without a C-level handler.
            if signal.getsignal(sig) is not None:
                signal.signal(sig, signal.signal(sig, handler))
                checked.add(sig)
        # Issue #18396: Ensure the above loop at least tested *something*
        self.assertTrue(checked)

        with self.assertRaises(ValueError):
            signal.signal(-1, handler)

        with self.assertRaises(ValueError):
            signal.signal(7, handler)
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:compatify    作者:hatooku    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:Data-visualization    作者:insta-code1    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def init_signals(self):
        # Set up signals through the event loop API.

        self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
                                     signal.SIGQUIT, None)

        self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
                                     signal.SIGTERM, None)

        self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
                                     signal.SIGINT, None)

        self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
                                     signal.SIGWINCH, None)

        self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
                                     signal.SIGUSR1, None)

        self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
                                     signal.SIGABRT, None)

        # Don't let SIGTERM and SIGUSR1 disturb active requests
        # by interrupting system calls
        signal.siginterrupt(signal.SIGTERM, False)
        signal.siginterrupt(signal.SIGUSR1, False)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_issue9324(self):
        # Updated for issue #10003, adding SIGBREAK
        handler = lambda x, y: None
        checked = set()
        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
                    signal.SIGTERM):
            # Set and then reset a handler for signals that work on windows.
            # Issue #18396, only for signals without a C-level handler.
            if signal.getsignal(sig) is not None:
                signal.signal(sig, signal.signal(sig, handler))
                checked.add(sig)
        # Issue #18396: Ensure the above loop at least tested *something*
        self.assertTrue(checked)

        with self.assertRaises(ValueError):
            signal.signal(-1, handler)

        with self.assertRaises(ValueError):
            signal.signal(7, handler)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:deluge-telegramer    作者:noam09    | 项目源码 | 文件源码
def idle(self, stop_signals=(SIGINT, SIGTERM, SIGABRT)):
        """Blocks until one of the signals are received and stops the updater.

        Args:
            stop_signals (:obj:`iterable`): Iterable containing signals from the signal module that
                should be subscribed to. Updater.stop() will be called on receiving one of those
                signals. Defaults to (``SIGINT``, ``SIGTERM``, ``SIGABRT``).

        """
        for sig in stop_signals:
            signal(sig, self.signal_handler)

        self.is_idle = True

        while self.is_idle:
            sleep(1)
项目:Lixiang_zhaoxin    作者:hejaxian    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def murder_workers(self):
        """\
        Kill unused/idle workers
        """
        if not self.timeout:
            return
        workers = list(self.WORKERS.items())
        for (pid, worker) in workers:
            try:
                if time.time() - worker.tmp.last_update() <= self.timeout:
                    continue
            except (OSError, ValueError):
                continue

            if not worker.aborted:
                self.log.critical("WORKER TIMEOUT (pid:%s)", pid)
                worker.aborted = True
                self.kill_worker(pid, signal.SIGABRT)
            else:
                self.kill_worker(pid, signal.SIGKILL)
项目:guvnor    作者:jeamland    | 项目源码 | 文件源码
def init_signals(self):
        # Set up signals through the event loop API.

        self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
                                     signal.SIGQUIT, None)

        self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
                                     signal.SIGTERM, None)

        self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
                                     signal.SIGINT, None)

        self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
                                     signal.SIGWINCH, None)

        self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
                                     signal.SIGUSR1, None)

        self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
                                     signal.SIGABRT, None)

        # Don't let SIGTERM and SIGUSR1 disturb active requests
        # by interrupting system calls
        signal.siginterrupt(signal.SIGTERM, False)
        signal.siginterrupt(signal.SIGUSR1, False)
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def display(self):
        error("Program received signal SIGABRT, Aborted.")
项目:darkc0de-old-stuff    作者:tuwid    | 项目源码 | 文件源码
def _analyze(self):
        if self.signum == SIGSEGV:
            self.memoryFault()
        elif self.signum == SIGFPE:
            self.mathError()
        elif self.signum == SIGCHLD:
            self.childExit()
        elif self.signum == SIGABRT:
            self.error = Abort()
        return self.error
项目:uvicorn    作者:encode    | 项目源码 | 文件源码
def init_signals(self):
        # Set up signals through the event loop API.
        loop = asyncio.get_event_loop()

        loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
                                signal.SIGQUIT, None)

        loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
                                signal.SIGTERM, None)

        loop.add_signal_handler(signal.SIGINT, self.handle_quit,
                                signal.SIGINT, None)

        loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
                                signal.SIGWINCH, None)

        loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
                                signal.SIGUSR1, None)

        loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
                                signal.SIGABRT, None)

        # Don't let SIGTERM and SIGUSR1 disturb active requests
        # by interrupting system calls
        signal.siginterrupt(signal.SIGTERM, False)
        signal.siginterrupt(signal.SIGUSR1, False)
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def setUp(self):
        self.sigint_fired = False
        self.sigabrt_fired = False

        signal.signal(signal.SIGABRT, self.sigabrt_handler)
        signal.signal(signal.SIGINT, self.sigint_handler)
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_no_int_case_local_killer(self):
        test_process_obj = TestProcess()
        testing_process = multiprocessing.Process(
            target=test_process_obj.no_int_sleep,
            kwargs={
                'interval': 30,
            },
        )
        testing_process.daemon = True
        testing_process.start()

        self.assertTrue(testing_process.is_alive())

        local_killer = devices.killer.LocalKiller(
            pid=testing_process.pid,
            soft_timeout=1.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=2.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=5.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        local_killer.start()
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertFalse(testing_process.is_alive())
        self.assertEqual(testing_process.exitcode, 10)
        local_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_sleep_case_remote_killer(self):
        test_process_obj = TestProcess()
        testing_process = multiprocessing.Process(
            target=test_process_obj.sleep,
            kwargs={
                'interval': 30,
            },
        )
        testing_process.daemon = True
        testing_process.start()

        self.assertTrue(testing_process.is_alive())

        remote_killer = devices.killer.RemoteKiller(
            pid=testing_process.pid,
            soft_timeout=1.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=2.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=5.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        remote_killer.start()
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertFalse(testing_process.is_alive())
        self.assertEqual(testing_process.exitcode, 20)
        remote_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_no_int_case_remote_killer(self):
        test_process_obj = TestProcess()
        testing_process = multiprocessing.Process(
            target=test_process_obj.no_int_sleep,
            kwargs={
                'interval': 30,
            },
        )
        testing_process.daemon = True
        testing_process.start()

        self.assertTrue(testing_process.is_alive())

        remote_killer = devices.killer.RemoteKiller(
            pid=testing_process.pid,
            soft_timeout=1.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=2.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=5.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        remote_killer.start()
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertFalse(testing_process.is_alive())
        self.assertEqual(testing_process.exitcode, 10)
        remote_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def test_lost_case_remote_killer(self):
        test_process_obj = TestProcess()
        testing_process = multiprocessing.Process(
            target=test_process_obj.lost,
            kwargs={
                'interval': 30,
            },
        )
        testing_process.daemon = True
        testing_process.start()

        self.assertTrue(testing_process.is_alive())

        remote_killer = devices.killer.RemoteKiller(
            pid=testing_process.pid,
            soft_timeout=1.0,
            soft_timeout_signal=signal.SIGINT,
            hard_timeout=2.0,
            hard_timeout_signal=signal.SIGABRT,
            critical_timeout=3.0,
            critical_timeout_signal=signal.SIGTERM,
            memory_limit=4 * 1024 * 1024 * 1024,
            memory_limit_signal=signal.SIGINT,
        )

        remote_killer.start()
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertTrue(testing_process.is_alive())
        time.sleep(1.2)
        self.assertFalse(testing_process.is_alive())
        self.assertEqual(testing_process.exitcode, -15)
        remote_killer.stop()
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def init(self):
        '''
        '''
        signal.signal(signal.SIGABRT, self.sigabrt_handler)
        signal.signal(signal.SIGINT, self.sigint_handler)
项目:tasker    作者:wavenator    | 项目源码 | 文件源码
def end_working(
        self,
    ):
        if self.tasks_to_finish:
            self.worker_task_queue.apply_async_many(
                tasks=self.tasks_to_finish,
                priority='NORMAL',
            )

        signal.signal(signal.SIGABRT, signal.SIG_DFL)
        signal.signal(signal.SIGINT, signal.SIG_DFL)

        self.killer.stop()
项目:vault-redirector-twisted    作者:manheim    | 项目源码 | 文件源码
def test_handle_logging_signal_other(self):
        self.cls.log_enabled = True
        with patch('%s.logger' % pbm) as mock_logger:
            with patch('%s.getpid' % pbm) as mock_getpid:
                mock_getpid.return_value = 12345
                self.cls.handle_logging_signal(signal.SIGABRT, None)
        assert mock_logger.mock_calls == []
        assert self.cls.log_enabled is True
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_issue9324(self):
        # Updated for issue #10003, adding SIGBREAK
        handler = lambda x, y: None
        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
                    signal.SIGTERM):
            # Set and then reset a handler for signals that work on windows
            signal.signal(sig, signal.signal(sig, handler))

        with self.assertRaises(ValueError):
            signal.signal(-1, handler)

        with self.assertRaises(ValueError):
            signal.signal(7, handler)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_run_abort(self):
        # returncode handles signal termination
        with _SuppressCoreFiles():
            p = subprocess.Popen([sys.executable, "-c",
                                  'import os; os.abort()'])
            p.wait()
        self.assertEqual(-p.returncode, signal.SIGABRT)
项目:AlexaBeagleBone2    作者:merdahl    | 项目源码 | 文件源码
def setup():
    for sig in (signal.SIGABRT, signal.SIGILL, signal.SIGINT, signal.SIGSEGV, signal.SIGTERM):
        signal.signal(sig, cleanup)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def _test_bug_551(self, query):
        script = ("""\
import os
import sys
import time
import signal
import threading

import psycopg2

def handle_sigabort(sig, frame):
    sys.exit(1)

def killer():
    time.sleep(0.5)
    os.kill(os.getpid(), signal.SIGABRT)

signal.signal(signal.SIGABRT, handle_sigabort)

conn = psycopg2.connect(%(dsn)r)

cur = conn.cursor()

cur.execute("create table test551 (id serial, num varchar(50))")

t = threading.Thread(target=killer)
t.daemon = True
t.start()

while True:
    cur.execute(%(query)r, ("Hello, world!",))
""" % {'dsn': dsn, 'query': query})

        proc = sp.Popen([sys.executable, '-c', script_to_py3(script)],
            stdout=sp.PIPE, stderr=sp.PIPE)
        (out, err) = proc.communicate()
        self.assertNotEqual(proc.returncode, 0)
        # Strip [NNN refs] from output
        err = re.sub(br'\[[^\]]+\]', b'', err).strip()
        self.assertTrue(not err, err)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_issue9324(self):
        # Updated for issue #10003, adding SIGBREAK
        handler = lambda x, y: None
        for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
                    signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
                    signal.SIGTERM):
            # Set and then reset a handler for signals that work on windows
            signal.signal(sig, signal.signal(sig, handler))

        with self.assertRaises(ValueError):
            signal.signal(-1, handler)

        with self.assertRaises(ValueError):
            signal.signal(7, handler)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_run_abort(self):
        # returncode handles signal termination
        with _SuppressCoreFiles():
            p = subprocess.Popen([sys.executable, "-c",
                                  "import os; os.abort()"])
            p.wait()
        self.assertEqual(-p.returncode, signal.SIGABRT)