Python signal 模块,Signals() 实例源码

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

项目:getproxy    作者:fate0    | 项目源码 | 文件源码
def signal_name(signum):
    try:
        if sys.version_info[:2] >= (3, 5):
            return signal.Signals(signum).name
        else:
            return _signames[signum]

    except KeyError:
        return 'SIG_UNKNOWN'
    except ValueError:
        return 'SIG_UNKNOWN'
项目:algochecker-engine    作者:algochecker    | 项目源码 | 文件源码
def sigterm_handler(signum, frame):
    logging.warning('Received {}, will terminate soon after finishing current job.'.format(signal.Signals(signum).name))
    task_queue.interrupted = True
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def wait(self):
        '''
        Wait for a single signal from the signal set to arrive.
        '''
        if not self.watching:
            async with self:
                return await self.wait()

        while True:
            if self.pending:
                return signal.Signals(self.pending.popleft())
            await _sigwait(self)
项目:zielen    作者:lostatc    | 项目源码 | 文件源码
def signal_exception_handler(signum: int, frame) -> None:
    """Raise an exception with error message for an interruption by signal."""
    raise ProgramError("program received " + signal.Signals(signum).name)
项目:motion-detection    作者:fabiojmendes    | 项目源码 | 文件源码
def stop_running(self, signum, frame):
        print("Stopping execution due to a {} signal".format(signal.Signals(signum).name))
        self.running = False
项目:arq    作者:samuelcolvin    | 项目源码 | 文件源码
def handle_sig(self, signum):
        self.running = False
        work_logger.info('pid=%d, got signal: %s, stopping...', os.getpid(), Signals(signum).name)
        signal.signal(SIG_PROXY, signal.SIG_IGN)
        self._set_force_handler()
项目:arq    作者:samuelcolvin    | 项目源码 | 文件源码
def handle_sig_force(self, signum, frame):
        work_logger.warning('pid=%d, got signal: %s again, forcing exit', os.getpid(), Signals(signum).name)
        raise ImmediateExit('force exit')
项目:arq    作者:samuelcolvin    | 项目源码 | 文件源码
def handle_sig(self, signum, frame):
        signal.signal(signal.SIGINT, self.handle_sig_force)
        signal.signal(signal.SIGTERM, self.handle_sig_force)
        ctrl_logger.info('got signal: %s, waiting for worker pid=%s to finish...', Signals(signum).name,
                         self.process and self.process.pid)
        # sleep to make sure worker.handle_sig above has executed if it's going to and detached handle_proxy_signal
        time.sleep(0.01)
        if self.process and self.process.is_alive():
            ctrl_logger.debug("sending custom shutdown signal to worker in case it didn't receive the signal")
            os.kill(self.process.pid, SIG_PROXY)
项目:arq    作者:samuelcolvin    | 项目源码 | 文件源码
def handle_sig_force(self, signum, frame):
        ctrl_logger.warning('got signal: %s again, forcing exit', Signals(signum).name)
        if self.process and self.process.is_alive():
            ctrl_logger.error('sending worker %d SIGTERM', self.process.pid)
            os.kill(self.process.pid, signal.SIGTERM)
        raise ImmediateExit('force exit')