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


Python signal.CTRL_BREAK_EVENT属性代码示例

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


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

示例1: test_kill_terminate

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def test_kill_terminate(self):
        # subprocess.Popen()'s terminate(), kill() and send_signal() do
        # not raise exception after the process is gone. psutil.Popen
        # diverges from that.
        cmd = [PYTHON_EXE, "-c", "import time; time.sleep(60);"]
        with psutil.Popen(cmd, stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE) as proc:
            proc.terminate()
            proc.wait()
            self.assertRaises(psutil.NoSuchProcess, proc.terminate)
            self.assertRaises(psutil.NoSuchProcess, proc.kill)
            self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                              signal.SIGTERM)
            if WINDOWS and sys.version_info >= (2, 7):
                self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                                  signal.CTRL_C_EVENT)
                self.assertRaises(psutil.NoSuchProcess, proc.send_signal,
                                  signal.CTRL_BREAK_EVENT) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_process.py

示例2: process_stop

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def process_stop(self):
        """Stop soapy_power process"""
        with self._shutdown_lock:
            if self.process:
                if self.process.poll() is None:
                    try:
                        if sys.platform == 'win32':
                            self.process.send_signal(signal.CTRL_BREAK_EVENT)
                        else:
                            self.process.terminate()
                    except ProcessLookupError:
                        pass
                self.process.wait()
                self.process = None

                # Close pipe used for communication with soapy_power process
                self.pipe_read.close()

                self.pipe_read = None
                self.pipe_read_fd = None
                self.pipe_write_fd = None
                self.pipe_write_handle = None 
开发者ID:xmikos,项目名称:qspectrumanalyzer,代码行数:24,代码来源:soapy_power.py

示例3: terminate_process

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def terminate_process(proc: Any, timeout: int = 15) -> None:
    if proc.poll() is None:

        # Sigint (keyboard interupt)
        if sys.platform.startswith("win"):
            proc.send_signal(signal.CTRL_BREAK_EVENT)
        else:
            proc.send_signal(signal.SIGINT)

        try:
            start = time.time()
            while (proc.poll() is None) and (time.time() < (start + timeout)):
                time.sleep(0.02)

        # Flat kill
        finally:
            proc.kill() 
开发者ID:MolSSI,项目名称:QCEngine,代码行数:19,代码来源:util.py

示例4: _default_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
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) 
开发者ID:Muterra,项目名称:py_daemoniker,代码行数:25,代码来源:_signals_windows.py

示例5: terminate

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def terminate(self):
    """Tries to do something saner on Windows that the stdlib.

    Windows:
      self.detached/CREATE_NEW_PROCESS_GROUP determines what can be used:
      - If set, only SIGBREAK can be sent and it is sent to a single process.
      - If not set, in theory only SIGINT can be used and *all processes* in
         the processgroup receive it. In practice, we just kill the process.
      See http://msdn.microsoft.com/library/windows/desktop/ms683155.aspx
      The default on Windows is to call TerminateProcess() always, which is not
      useful.

    On Posix, always send SIGTERM.
    """
    try:
      if sys.platform == 'win32' and self.detached:
        return self.send_signal(signal.CTRL_BREAK_EVENT)
      super(Popen, self).terminate()
    except OSError:
      # The function will throw if the process terminated in-between. Swallow
      # this.
      pass 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:subprocess42.py

示例6: reap_process_group

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def reap_process_group(*args):
    def sigterm_handler(*args):
        # Give a one-second grace period for other processes to clean up.
        time.sleep(SIGTERM_GRACE_PERIOD_SECONDS)
        # SIGKILL the pgroup (including ourselves) as a last-resort.
        if sys.platform == "win32":
            atexit.unregister(sigterm_handler)
            os.kill(0, signal.CTRL_BREAK_EVENT)
        else:
            os.killpg(0, signal.SIGKILL)

    # Set a SIGTERM handler to handle SIGTERMing ourselves with the group.
    if sys.platform == "win32":
        atexit.register(sigterm_handler)
    else:
        signal.signal(signal.SIGTERM, sigterm_handler)

    # Our parent must have died, SIGTERM the group (including ourselves).
    if sys.platform == "win32":
        os.kill(0, signal.CTRL_C_EVENT)
    else:
        os.killpg(0, signal.SIGTERM) 
开发者ID:ray-project,项目名称:ray,代码行数:24,代码来源:ray_process_reaper.py

示例7: terminate

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def terminate(proc):
    if flags:
        proc.send_signal(CTRL_BREAK_EVENT)
    else:
        proc.terminate() 
开发者ID:huge-success,项目名称:sanic,代码行数:7,代码来源:test_reloader.py

示例8: send_signal

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def send_signal(self, sig):
            """Send a signal to the process
            """
            if sig == signal.SIGTERM:
                self.terminate()
            elif sig == signal.CTRL_C_EVENT:
                os.kill(self.pid, signal.CTRL_C_EVENT)
            elif sig == signal.CTRL_BREAK_EVENT:
                os.kill(self.pid, signal.CTRL_BREAK_EVENT)
            else:
                raise ValueError("Unsupported signal: {}".format(sig)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:13,代码来源:subprocess.py

示例9: _kill

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def _kill(proc, gid):
    """Kills the process as gracefully as possible:

      * Send CTRL_BREAK_EVENT (to the process group, there's no other way)
      * Give main process 30s to quit.
      * Call TerminateProcess on the process we spawned.

    Unfortunately, we don't have a mechanism to do 'TerminateProcess' to the
    process's group, so this could leak processes on Windows.

    Returns the process's returncode.
    """
    # TODO(iannucci): Use a Job Object for process management. Use subprocess42
    # for reference.
    del gid  # gid is not supported on Windows
    try:
      # pylint: disable=no-member
      proc.send_signal(signal.CTRL_BREAK_EVENT)
    except OSError:
      pass
    # TODO(iannucci): This API changes in python3 to raise an exception on
    # timeout.
    proc.wait(timeout=30)
    if proc.returncode is not None:
      return proc.returncode
    try:
      proc.terminate()
    except OSError:
      pass
    return proc.wait() 
开发者ID:luci,项目名称:recipes-py,代码行数:32,代码来源:subproc.py

示例10: interrupt

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def interrupt(self) -> None:
        import signal
        try:
            self._inferior.send_signal(signal.SIGINT)
        except ValueError:  # pragma: no cover
            # On Windows, SIGINT is not supported, and CTRL_C_EVENT does nothing.
            self._inferior.send_signal(signal.CTRL_BREAK_EVENT) 
开发者ID:UAVCAN,项目名称:pyuavcan,代码行数:9,代码来源:_subprocess.py

示例11: test_CTRL_BREAK_EVENT

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def test_CTRL_BREAK_EVENT(self):
        self._kill_with_event(signal.CTRL_BREAK_EVENT, "CTRL_BREAK_EVENT") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_os.py

示例12: _ctrl_handler

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def _ctrl_handler(sig):
    """Handle a sig event and return 0 to terminate the process"""
    if sig == signal.CTRL_C_EVENT:
        pass
    elif sig == signal.CTRL_BREAK_EVENT:
        pass
    else:
        print("UNKNOWN EVENT")
    return 0 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:win_console_handler.py

示例13: test_ctrl_signals

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def test_ctrl_signals(self):
        p = psutil.Process(get_test_subprocess().pid)
        p.send_signal(signal.CTRL_C_EVENT)
        p.send_signal(signal.CTRL_BREAK_EVENT)
        p.kill()
        p.wait()
        self.assertRaises(psutil.NoSuchProcess,
                          p.send_signal, signal.CTRL_C_EVENT)
        self.assertRaises(psutil.NoSuchProcess,
                          p.send_signal, signal.CTRL_BREAK_EVENT) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_windows.py

示例14: test_ctrl_signals

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def test_ctrl_signals(self):
        p = psutil.Process(self.spawn_testproc().pid)
        p.send_signal(signal.CTRL_C_EVENT)
        p.send_signal(signal.CTRL_BREAK_EVENT)
        p.kill()
        p.wait()
        self.assertRaises(psutil.NoSuchProcess,
                          p.send_signal, signal.CTRL_C_EVENT)
        self.assertRaises(psutil.NoSuchProcess,
                          p.send_signal, signal.CTRL_BREAK_EVENT) 
开发者ID:giampaolo,项目名称:psutil,代码行数:12,代码来源:test_windows.py

示例15: interrupt_handled_subprocess

# 需要导入模块: import signal [as 别名]
# 或者: from signal import CTRL_BREAK_EVENT [as 别名]
def interrupt_handled_subprocess(
    cmd, verbose=False, return_object=True, write_to_stdout=False, combine_stderr=True,
    block=True, nospin=True, env=None
):
    """Given a :class:`subprocess.Popen` instance, wrap it in exception handlers.

    Terminates the subprocess when and if a `SystemExit` or `KeyboardInterrupt` are
    processed.

    Arguments:
        :param str cmd: A command to run
        :param bool verbose: Whether to run with verbose mode enabled, default False
        :param bool return_object: Whether to return a subprocess instance or a 2-tuple, default True
        :param bool write_to_stdout: Whether to write directly to stdout, default False
        :param bool combine_stderr: Whether to combine stdout and stderr, default True
        :param bool block: Whether the subprocess should be a blocking subprocess, default True
        :param bool nospin: Whether to suppress the spinner with the subprocess, default True
        :param Optional[Dict[str, str]] env: A dictionary to merge into the subprocess environment
        :return: A subprocess, wrapped in exception handlers, as a context manager
        :rtype: :class:`subprocess.Popen` obj: An instance of a running subprocess
    """
    obj = run(
        cmd, verbose=verbose, return_object=True, write_to_stdout=False,
        combine_stderr=False, block=True, nospin=True, env=env,
    )
    try:
        yield obj
    except (SystemExit, KeyboardInterrupt):
        if os.name == "nt":
            os.kill(obj.pid, signal.CTRL_BREAK_EVENT)
        else:
            os.kill(obj.pid, signal.SIGINT)
        obj.wait()
        raise 
开发者ID:pypa,项目名称:pipenv,代码行数:36,代码来源:utils.py


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