當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。