當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.SIGSEGV屬性代碼示例

本文整理匯總了Python中signal.SIGSEGV屬性的典型用法代碼示例。如果您正苦於以下問題:Python signal.SIGSEGV屬性的具體用法?Python signal.SIGSEGV怎麽用?Python signal.SIGSEGV使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在signal的用法示例。


在下文中一共展示了signal.SIGSEGV屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_run_async_exit_code

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def test_run_async_exit_code(self):

        def run_with_exit_code_0(process_idx):
            sys.exit(0)

        def run_with_exit_code_11(process_idx):
            os.kill(os.getpid(), signal.SIGSEGV)

        with warnings.catch_warnings(record=True) as ws:
            async_.run_async(4, run_with_exit_code_0)
            # There should be no AbnormalExitWarning
            self.assertEqual(
                sum(1 if issubclass(
                    w.category, async_.AbnormalExitWarning) else 0
                    for w in ws), 0)

        with warnings.catch_warnings(record=True) as ws:
            async_.run_async(4, run_with_exit_code_11)
            # There should be 4 AbnormalExitWarning
            self.assertEqual(
                sum(1 if issubclass(
                    w.category, async_.AbnormalExitWarning) else 0
                    for w in ws), 4) 
開發者ID:chainer,項目名稱:chainerrl,代碼行數:25,代碼來源:test_async.py

示例2: test_debug_crash_segfault

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def test_debug_crash_segfault():
    """Verify that debug_crash crashes as intended."""
    caught = False

    def _handler(num, frame):
        """Temporary handler for segfault."""
        nonlocal caught
        caught = num == signal.SIGSEGV

    with _trapped_segv(_handler):
        # since we handle the segfault, execution will continue and run into
        # the "Segfault failed (wat.)" Exception
        with pytest.raises(Exception, match="Segfault failed"):
            misccommands.debug_crash(typ='segfault')
        time.sleep(0.001)
    assert caught 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:18,代碼來源:test_misccommands.py

示例3: _SigSegvHandler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def _SigSegvHandler(self, signal_number, stack_frame):
    """Signal handler for the SIGSEGV signal.

    Args:
      signal_number (int): numeric representation of the signal.
      stack_frame (frame): current stack frame or None.
    """
    self._OnCriticalError()

    # Note that the original SIGSEGV handler can be 0.
    if self._original_sigsegv_handler is not None:
      # Let the original SIGSEGV handler take over.
      signal.signal(signal.SIGSEGV, self._original_sigsegv_handler)
      os.kill(self._pid, signal.SIGSEGV)

  # pylint: disable=unused-argument 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:18,代碼來源:base_process.py

示例4: test_issue9324

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:test_signal.py

示例5: _default_handler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [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

示例6: sig2exc

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def sig2exc(sig, frm):
            """ signal handler """

            error = PilotErrors()
            runJob.setGlobalPilotErrorDiag("!!FAILED!!3000!! SIGTERM Signal %s is caught in child pid=%d!\n" % (sig, os.getpid()))
            tolog(runJob.getGlobalPilotErrorDiag())
            if sig == signal.SIGTERM:
                runJob.setGlobalErrorCode(error.ERR_SIGTERM)
            elif sig == signal.SIGQUIT:
                runJob.setGlobalErrorCode(error.ERR_SIGQUIT)
            elif sig == signal.SIGSEGV:
                runJob.setGlobalErrorCode(error.ERR_SIGSEGV)
            elif sig == signal.SIGXCPU:
                runJob.setGlobalErrorCode(error.ERR_SIGXCPU)
            elif sig == signal.SIGBUS:
                runJob.setGlobalErrorCode(error.ERR_SIGBUS)
            elif sig == signal.SIGUSR1:
                runJob.setGlobalErrorCode(error.ERR_SIGUSR1)
            else:
                runJob.setGlobalErrorCode(error.ERR_KILLSIGNAL)
            runJob.setFailureCode(runJob.getGlobalErrorCode)
            # print to stderr
            print >> sys.stderr, runJob.getGlobalPilotErrorDiag()
            raise SystemError(sig) 
開發者ID:PanDAWMS,項目名稱:pilot,代碼行數:26,代碼來源:RunJobEdison.py

示例7: sig2exc

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def sig2exc(sig, frm):
            """ signal handler """

            error = PilotErrors()
            runJob.setGlobalPilotErrorDiag("!!FAILED!!3000!! SIGTERM Signal %s is caught in child pid=%d!\n" % (sig, os.getpid()))
            tolog(runJob.getGlobalPilotErrorDiag())
            if sig == signal.SIGTERM:
                runJob.setGlobalErrorCode(error.ERR_SIGTERM)
            elif sig == signal.SIGQUIT:
                runJob.setGlobalErrorCode(error.ERR_SIGQUIT)
            elif sig == signal.SIGSEGV:
                runJob.setGlobalErrorCode(error.ERR_SIGSEGV)
            elif sig == signal.SIGXCPU:
                runJob.setGlobalErrorCode(error.ERR_SIGXCPU)
            elif sig == signal.SIGBUS:
                runJob.setGlobalErrorCode(error.ERR_SIGBUS)
            elif sig == signal.SIGUSR1:
                runJob.setGlobalErrorCode(error.ERR_SIGUSR1)
            else:
                runJob.setGlobalErrorCode(error.ERR_KILLSIGNAL)
            runJob.setFailureCode(runJob.getGlobalErrorCode())
            # print to stderr
            print >> sys.stderr, runJob.getGlobalPilotErrorDiag()
            raise SystemError(sig) 
開發者ID:PanDAWMS,項目名稱:pilot,代碼行數:26,代碼來源:RunJob.py

示例8: run

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def run(self):
        if os.path.isfile(self.__executable):
            result = subprocess.run(self.__executable, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

            output = result.stdout.decode('utf-8')
            print(output)

            exit_code = result.returncode
            if exit_code == EExitCode.success:
                exit(exit_code)
            elif exit_code == -signal.SIGSEGV:
                logging.error("Segmentation fault signal is received during unit-testing process.")
                exit(exit_code)

            for _ in range(self.__attempts):
                exit_code, output = self.__rerun(output)
                if exit_code == EExitCode.success:
                    exit(exit_code)
                elif exit_code == EExitCode.failure_tests_not_found:
                    logging.error("There is nothing to rerun - failure tests are not found despite failure code '"
                                  + str(result.returncode) + "'.")
                    exit(exit_code)
        else:
            logging.error("Impossible to find executable file '%s'." % self.__executable)
            exit(EExitCode.executable_not_found) 
開發者ID:annoviko,項目名稱:pyclustering,代碼行數:27,代碼來源:ut-runner.py

示例9: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def __init__(self, _args=None) -> None:
        super().__init__()
        self.windowTitleChanged.connect(self.on_windowTitleChanged)
        with open_in_directory_of(__file__, "mainwindow.ui") as file:
            uic.loadUi(file, self, package="application.ui")

        for sig in (signal.SIGABRT, signal.SIGINT, signal.SIGSEGV, signal.SIGTERM):
            signal.signal(sig, lambda signal, frame: self.handle_signal(signal))

        # catch the interpreter every now and then to be able to catch signals
        self.idle_timer = QtCore.QTimer()
        self.idle_timer.timeout.connect(lambda: None)
        self.idle_timer.start(200)

        log().info("app dir: %r", application_root_dir())

        self.setMouseTracking(True) 
開發者ID:frans-fuerst,項目名稱:track,代碼行數:19,代碼來源:mainwindow.py

示例10: _trapped_segv

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def _trapped_segv(handler):
    """Temporarily install given signal handler for SIGSEGV."""
    old_handler = signal.signal(signal.SIGSEGV, handler)
    yield
    if old_handler is not None:
        signal.signal(signal.SIGSEGV, old_handler) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:8,代碼來源:test_misccommands.py

示例11: debug_crash

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def debug_crash(typ: str = 'exception') -> None:
    """Crash for debugging purposes.

    Args:
        typ: either 'exception' or 'segfault'.
    """
    if typ == 'segfault':
        os.kill(os.getpid(), signal.SIGSEGV)
        raise Exception("Segfault failed (wat.)")
    raise Exception("Forced crash") 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:12,代碼來源:misccommands.py

示例12: __interceptSignals

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def __interceptSignals(self):
        """Intercepts common signals"""
        for signum in [signal.SIGABRT,          # abnormal termination
                       signal.SIGFPE,           # floating point exception
                       signal.SIGILL,           # illegal instruction
                       signal.SIGSEGV]:         # segmentation violation
            signal.signal(signum, self.__signalHandler) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:9,代碼來源:clientbase_cdm_dbg.py

示例13: __signalHandler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def __signalHandler(self, signalNumber, stackFrame):
        """Handles signals"""
        if signalNumber == signal.SIGABRT:
            message = "Abnormal Termination"
        elif signalNumber == signal.SIGFPE:
            message = "Floating Point Exception"
        elif signalNumber == signal.SIGILL:
            message = "Illegal Instruction"
        elif signalNumber == signal.SIGSEGV:
            message = "Segmentation Violation"
        else:
            message = "Unknown Signal '{0}'".format(signalNumber)

        filename = self.absPath(stackFrame.f_code.co_filename)

        linenr = stackFrame.f_lineno
        ffunc = stackFrame.f_code.co_name

        if ffunc == '?':
            ffunc = ''

        if ffunc and not ffunc.startswith('<'):
            argInfo = getArgValues(stackFrame)
            try:
                fargs = formatArgValues(
                    argInfo.args, argInfo.varargs,
                    argInfo.keywords, argInfo.locals)
            except Exception:
                fargs = ''
        else:
            fargs = ''

        sendJSONCommand(self.socket, METHOD_SIGNAL,
                        self.procuuid,
                        {'message': message, 'filename': filename,
                         'linenumber': linenr, 'function': ffunc,
                         'arguments': fargs}) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:39,代碼來源:clientbase_cdm_dbg.py

示例14: test_issue9324

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_signal.py

示例15: test_module_constants

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIGSEGV [as 別名]
def test_module_constants(self):
        self.assertEqual(signal.NSIG, 23)
        self.assertEqual(signal.SIGABRT, 22)
        self.assertEqual(signal.SIGBREAK, 21)
        self.assertEqual(signal.SIGFPE, 8)
        self.assertEqual(signal.SIGILL, 4)
        self.assertEqual(signal.SIGINT, 2)
        self.assertEqual(signal.SIGSEGV, 11)
        self.assertEqual(signal.SIGTERM, 15)
        self.assertEqual(signal.SIG_DFL, 0)
        self.assertEqual(signal.SIG_IGN, 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_signal.py


注:本文中的signal.SIGSEGV屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。