当前位置: 首页>>代码示例>>Python>>正文


Python signal.Signals方法代码示例

本文整理汇总了Python中signal.Signals方法的典型用法代码示例。如果您正苦于以下问题:Python signal.Signals方法的具体用法?Python signal.Signals怎么用?Python signal.Signals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在signal的用法示例。


在下文中一共展示了signal.Signals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_results_message

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def get_results_message(results: dict) -> Tuple[str, str]:
        """Return a user-friendly message and error corresponding to the process's return code."""
        stdout, returncode = results["stdout"], results["returncode"]
        msg = f"Your eval job has completed with return code {returncode}"
        error = ""

        if returncode is None:
            msg = "Your eval job has failed"
            error = stdout.strip()
        elif returncode == 128 + SIGKILL:
            msg = "Your eval job timed out or ran out of memory"
        elif returncode == 255:
            msg = "Your eval job has failed"
            error = "A fatal NsJail error occurred"
        else:
            # Try to append signal's name if one exists
            try:
                name = Signals(returncode - 128).name
                msg = f"{msg} ({name})"
            except ValueError:
                pass

        return msg, error 
开发者ID:python-discord,项目名称:bot,代码行数:25,代码来源:snekbox.py

示例2: __str__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def __str__(self):
            if self.returncode and self.returncode < 0:
                try:
                    return "Command '%s' died with %r." % (
                        self.cmd,
                        signal.Signals(-self.returncode),
                    )
                except ValueError:
                    return "Command '%s' died with unknown signal %d." % (
                        self.cmd,
                        -self.returncode,
                    )
            else:
                return "Command '%s' returned non-zero exit status %d." % (
                    self.cmd,
                    self.returncode,
                ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:19,代码来源:_compat.py

示例3: terminate_agents

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def terminate_agents(
        cls,
        *subprocesses: subprocess.Popen,
        signal: signal.Signals = signal.SIGINT,
        timeout: int = 10,
    ) -> None:
        """
        Terminate agent subprocesses.
        Run from agent's directory.

        :param subprocesses: the subprocesses running the agents
        :param signal: the signal for interuption
        :param timeout: the timeout for interuption
        """
        if not subprocesses:
            subprocesses = tuple(cls.subprocesses)
        for process in subprocesses:
            sigint_crossplatform(process)
        for process in subprocesses:
            process.wait(timeout=timeout) 
开发者ID:fetchai,项目名称:agents-aea,代码行数:22,代码来源:test_cases.py

示例4: _get_exitcode_name

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def _get_exitcode_name(exitcode):
    if sys.platform == "win32":
        # The exitcode are unreliable  on windows (see bpo-31863).
        # For this case, return UNKNOWN
        return "UNKNOWN"

    if exitcode < 0:
        try:
            import signal
            if sys.version_info > (3, 5):
                return signal.Signals(-exitcode).name

            # construct an inverse lookup table
            for v, k in signal.__dict__.items():
                if (v.startswith('SIG') and not v.startswith('SIG_') and
                        k == -exitcode):
                        return v
        except ValueError:
            return "UNKNOWN"
    elif exitcode != 255:
        # The exitcode are unreliable on forkserver were 255 is always returned
        # (see bpo-30589). For this case, return UNKNOWN
        return "EXIT"

    return "UNKNOWN" 
开发者ID:joblib,项目名称:loky,代码行数:27,代码来源:utils.py

示例5: signal_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def signal_handler(sig, frame):
    global program_running
    log.warning("Got signal, " + signal.Signals(sig).name + " terminating!")
    print("Got signal,", signal.Signals(sig).name, "terminating!")
    try:
        device.__exit__()
        log.info("Removed uinput device")
        print("Removed uinput device")
    except SystemExit:
        sys.exit(0)
    except Exception as e:
        print("Could not remove uinput device:",e)
        log.info("Could not remove uinput device:",e)

    # pid_handler.remove_pid()
    log.info("----------------------EXITING-----------------------")
    print("Exiting")
    program_running = False
    sys.exit(0) 
开发者ID:JSubelj,项目名称:g910-gkey-macro-support,代码行数:21,代码来源:g910_gkey_mapper.py

示例6: exit_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def exit_handler(signum, frame):
    log.info("Received %s, canceling jobs and exiting.", signal.Signals(signum).name)
    schedule.clear()
    exit()


############################################################
# MAIN
############################################################ 
开发者ID:l3uddz,项目名称:traktarr,代码行数:11,代码来源:traktarr.py

示例7: status_name

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def status_name(self) -> str:
        return signal.Signals(self.status).name 
开发者ID:offensive-hub,项目名称:black-widow,代码行数:4,代码来源:abstract_job_model.py

示例8: __enter__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def __enter__(self):
        self.signal_received = {}
        self.old_handlers = {}
        for sig in self.sigs:
            self.signal_received[sig] = False
            self.old_handlers[sig] = signal.getsignal(sig)
            def handler(s, frame):
                self.signal_received[sig] = (s, frame)
                # Note: in Python 3.5, you can use signal.Signals(sig).name
                logging.info('Signal %s received. Delaying KeyboardInterrupt.' % sig)
            self.old_handlers[sig] = signal.getsignal(sig)
            signal.signal(sig, handler) 
开发者ID:leanprover-community,项目名称:mathlib-tools,代码行数:14,代码来源:delayed_interrupt.py

示例9: signal_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def signal_handler(signal_number, frame):
    sig_name = signal.Signals(signal_number).name
    logger.info(f'Captured signal number {signal_number}. Name: {sig_name}') 
开发者ID:Ambro17,项目名称:AmbroBot,代码行数:5,代码来源:utils.py

示例10: __enter__

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def __enter__(self):
        self.signal_received = {}
        self.old_handlers = {}
        for sig in self.sigs:
            self.signal_received[sig] = False
            self.old_handlers[sig] = signal.getsignal(sig)
            def handler(s, frame):
                self.signal_received[sig] = (s, frame)
                # Note: in Python 3.5, you can use signal.Signals(sig).name
            self.old_handlers[sig] = signal.getsignal(sig)
            signal.signal(sig, handler) 
开发者ID:videoflow,项目名称:videoflow,代码行数:13,代码来源:generic_utils.py

示例11: _add_signal_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def _add_signal_handler(self, signum: Signals, handler: Callable[[Signals], None]) -> None:
        try:
            self.loop.add_signal_handler(signum, partial(handler, signum))
        except NotImplementedError:  # pragma: no cover
            logger.debug('Windows does not support adding a signal handler to an eventloop') 
开发者ID:samuelcolvin,项目名称:arq,代码行数:7,代码来源:worker.py

示例12: handle_sig

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def handle_sig(self, signum: Signals) -> None:
        sig = Signals(signum)
        logger.info(
            'shutdown on %s ◆ %d jobs complete ◆ %d failed ◆ %d retries ◆ %d ongoing to cancel',
            sig.name,
            self.jobs_complete,
            self.jobs_failed,
            self.jobs_retried,
            len(self.tasks),
        )
        for t in self.tasks:
            if not t.done():
                t.cancel()
        self.main_task and self.main_task.cancel()
        self.on_stop and self.on_stop(sig) 
开发者ID:samuelcolvin,项目名称:arq,代码行数:17,代码来源:worker.py

示例13: test_enums

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def test_enums(self):
        for name in dir(signal):
            sig = getattr(signal, name)
            if name in {'SIG_DFL', 'SIG_IGN'}:
                self.assertIsInstance(sig, signal.Handlers)
            elif name in {'SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'}:
                self.assertIsInstance(sig, signal.Sigmasks)
            elif name.startswith('SIG') and not name.startswith('SIG_'):
                self.assertIsInstance(sig, signal.Signals)
            elif name.startswith('CTRL_'):
                self.assertIsInstance(sig, signal.Signals)
                self.assertEqual(sys.platform, "win32") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_signal.py

示例14: test_sigpending

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def test_sigpending(self):
        code = """if 1:
            import os
            import signal

            def handler(signum, frame):
                1/0

            signum = signal.SIGUSR1
            signal.signal(signum, handler)

            signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
            os.kill(os.getpid(), signum)
            pending = signal.sigpending()
            for sig in pending:
                assert isinstance(sig, signal.Signals), repr(pending)
            if pending != {signum}:
                raise Exception('%s != {%s}' % (pending, signum))
            try:
                signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
            except ZeroDivisionError:
                pass
            else:
                raise Exception("ZeroDivisionError not raised")
        """
        assert_python_ok('-c', code) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:test_signal.py

示例15: test_sigwait

# 需要导入模块: import signal [as 别名]
# 或者: from signal import Signals [as 别名]
def test_sigwait(self):
        self.wait_helper(signal.SIGALRM, '''
        def test(signum):
            signal.alarm(1)
            received = signal.sigwait([signum])
            assert isinstance(received, signal.Signals), received
            if received != signum:
                raise Exception('received %s, not %s' % (received, signum))
        ''') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_signal.py


注:本文中的signal.Signals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。