Python faulthandler.disable() Examples
The following are 18
code examples of faulthandler.disable().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
faulthandler
, or try the search function
.
Example #1
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_is_enabled(self): orig_stderr = sys.stderr try: # regrtest may replace sys.stderr by io.StringIO object, but # faulthandler.enable() requires that sys.stderr has a fileno() # method sys.stderr = sys.__stderr__ was_enabled = faulthandler.is_enabled() try: faulthandler.enable() self.assertTrue(faulthandler.is_enabled()) faulthandler.disable() self.assertFalse(faulthandler.is_enabled()) finally: if was_enabled: faulthandler.enable() else: faulthandler.disable() finally: sys.stderr = orig_stderr
Example #2
Source File: crashsignal.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def destroy_crashlogfile(self): """Clean up the crash log file and delete it.""" if self._crash_log_file is None: return # We use sys.__stderr__ instead of sys.stderr here so this will still # work when sys.stderr got replaced, e.g. by "Python Tools for Visual # Studio". if sys.__stderr__ is not None: faulthandler.enable(sys.__stderr__) else: faulthandler.disable() # type: ignore[unreachable] try: self._crash_log_file.close() os.remove(self._crash_log_file.name) except OSError: log.destroy.exception("Could not remove crash log!")
Example #3
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_is_enabled(self): orig_stderr = sys.stderr try: # regrtest may replace sys.stderr by io.StringIO object, but # faulthandler.enable() requires that sys.stderr has a fileno() # method sys.stderr = sys.__stderr__ was_enabled = faulthandler.is_enabled() try: faulthandler.enable() self.assertTrue(faulthandler.is_enabled()) faulthandler.disable() self.assertFalse(faulthandler.is_enabled()) finally: if was_enabled: faulthandler.enable() else: faulthandler.disable() finally: sys.stderr = orig_stderr
Example #4
Source File: debug.py From tf-pose with Apache License 2.0 | 6 votes |
def enableFaulthandler(): """ Enable faulthandler for all threads. If the faulthandler package is available, this function disables and then re-enables fault handling for all threads (this is necessary to ensure any new threads are handled correctly), and returns True. If faulthandler is not available, then returns False. """ try: import faulthandler # necessary to disable first or else new threads may not be handled. faulthandler.disable() faulthandler.enable(all_threads=True) return True except ImportError: return False
Example #5
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_is_enabled(self): orig_stderr = sys.stderr try: # regrtest may replace sys.stderr by io.StringIO object, but # faulthandler.enable() requires that sys.stderr has a fileno() # method sys.stderr = sys.__stderr__ was_enabled = faulthandler.is_enabled() try: faulthandler.enable() self.assertTrue(faulthandler.is_enabled()) faulthandler.disable() self.assertFalse(faulthandler.is_enabled()) finally: if was_enabled: faulthandler.enable() else: faulthandler.disable() finally: sys.stderr = orig_stderr
Example #6
Source File: faulthandler.py From python-netsurv with MIT License | 5 votes |
def pytest_unconfigure(config): import faulthandler faulthandler.disable() # close our dup file installed during pytest_configure f = getattr(config, "fault_handler_stderr", None) if f is not None: # re-enable the faulthandler, attaching it to the default sys.stderr # so we can see crashes after pytest has finished, usually during # garbage collection during interpreter shutdown config.fault_handler_stderr.close() del config.fault_handler_stderr faulthandler.enable(file=_get_stderr_fileno())
Example #7
Source File: test_concurrent_futures.py From android_universal with MIT License | 5 votes |
def _crash(delay=None): """Induces a segfault.""" if delay: time.sleep(delay) import faulthandler faulthandler.disable() faulthandler._sigsegv()
Example #8
Source File: test_faulthandler.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_disable(self): code = """ import faulthandler faulthandler.enable() faulthandler.disable() faulthandler._sigsegv() """ not_expected = 'Fatal Python error' stderr, exitcode = self.get_output(code) stderr = '\n'.join(stderr) self.assertTrue(not_expected not in stderr, "%r is present in %r" % (not_expected, stderr)) self.assertNotEqual(exitcode, 0)
Example #9
Source File: test_faulthandler.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_disable(self): code = """ import faulthandler faulthandler.enable() faulthandler.disable() faulthandler._sigsegv() """ not_expected = 'Fatal Python error' stderr, exitcode = self.get_output(code) stderr = '\n'.join(stderr) self.assertTrue(not_expected not in stderr, "%r is present in %r" % (not_expected, stderr)) self.assertNotEqual(exitcode, 0)
Example #10
Source File: test_faulthandler.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_disable(self): code = """ import faulthandler faulthandler.enable() faulthandler.disable() faulthandler._sigsegv() """ not_expected = 'Fatal Python error' stderr, exitcode = self.get_output(code) stderr = '\n'.join(stderr) self.assertTrue(not_expected not in stderr, "%r is present in %r" % (not_expected, stderr)) self.assertNotEqual(exitcode, 0)
Example #11
Source File: faulthandler.py From pytest with MIT License | 5 votes |
def pytest_unconfigure(self, config: Config) -> None: import faulthandler faulthandler.disable() # close our dup file installed during pytest_configure # re-enable the faulthandler, attaching it to the default sys.stderr # so we can see crashes after pytest has finished, usually during # garbage collection during interpreter shutdown config._store[fault_handler_stderr_key].close() del config._store[fault_handler_stderr_key] faulthandler.enable(file=self._get_stderr_fileno())
Example #12
Source File: log.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def vdebug(self: logging.Logger, msg: str, *args: typing.Any, **kwargs: typing.Any) -> None: """Log with a VDEBUG level. VDEBUG is used when a debug message is rather verbose, and probably of little use to the end user or for post-mortem debugging, i.e. the content probably won't change unless the code changes. """ if self.isEnabledFor(VDEBUG_LEVEL): # pylint: disable=protected-access self._log(VDEBUG_LEVEL, msg, args, **kwargs) # pylint: enable=protected-access
Example #13
Source File: faulthandler.py From python-netsurv with MIT License | 5 votes |
def pytest_unconfigure(config): import faulthandler faulthandler.disable() # close our dup file installed during pytest_configure f = getattr(config, "fault_handler_stderr", None) if f is not None: # re-enable the faulthandler, attaching it to the default sys.stderr # so we can see crashes after pytest has finished, usually during # garbage collection during interpreter shutdown config.fault_handler_stderr.close() del config.fault_handler_stderr faulthandler.enable(file=_get_stderr_fileno())
Example #14
Source File: debug.py From tf-pose with Apache License 2.0 | 5 votes |
def finish(self, msg=None): """Add a final message; flush the message list if no parent profiler. """ if self._finished or self.disable: return self._finished = True if msg is not None: self(msg) self._newMsg("< Exiting %s, total time: %0.4f ms", self._name, (ptime.time() - self._firstTime) * 1000) type(self)._depth -= 1 if self._depth < 1: self.flush()
Example #15
Source File: debug.py From tf-pose with Apache License 2.0 | 5 votes |
def __call__(self, msg=None): """Register or print a new message with timing information. """ if self.disable: return if msg is None: msg = str(self._markCount) self._markCount += 1 newTime = ptime.time() self._newMsg(" %s: %0.4f ms", msg, (newTime - self._lastTime) * 1000) self._lastTime = newTime
Example #16
Source File: crashsignal.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def activate(self): """Set up signal handlers. On Windows this uses a QTimer to periodically hand control over to Python so it can handle signals. On Unix, it uses a QSocketNotifier with os.set_wakeup_fd to get notified. """ self._orig_handlers[signal.SIGINT] = signal.signal( signal.SIGINT, self.interrupt) self._orig_handlers[signal.SIGTERM] = signal.signal( signal.SIGTERM, self.interrupt) if utils.is_posix and hasattr(signal, 'set_wakeup_fd'): # pylint: disable=import-error,no-member,useless-suppression import fcntl read_fd, write_fd = os.pipe() for fd in [read_fd, write_fd]: flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) self._notifier = QSocketNotifier(typing.cast(sip.voidptr, read_fd), QSocketNotifier.Read, self) self._notifier.activated.connect( # type: ignore[attr-defined] self.handle_signal_wakeup) self._orig_wakeup_fd = signal.set_wakeup_fd(write_fd) # pylint: enable=import-error,no-member,useless-suppression else: self._timer.start(1000) self._timer.timeout.connect(lambda: None) self._activated = True
Example #17
Source File: log.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def ignore_py_warnings(**kwargs: typing.Any) -> typing.Iterator[None]: """Contextmanager to temporarily disable certain Python warnings.""" warnings.filterwarnings('ignore', **kwargs) yield if _log_inited: _init_py_warnings()
Example #18
Source File: log.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def init_log(args: argparse.Namespace) -> None: """Init loggers based on the argparse namespace passed.""" level = (args.loglevel or "info").upper() try: numeric_level = getattr(logging, level) except AttributeError: raise ValueError("Invalid log level: {}".format(args.loglevel)) if numeric_level > logging.DEBUG and args.debug: numeric_level = logging.DEBUG console, ram = _init_handlers(numeric_level, args.color, args.force_color, args.json_logging, args.loglines) root = logging.getLogger() global console_filter if console is not None: console_filter = LogFilter.parse(args.logfilter) console.addFilter(console_filter) root.addHandler(console) if ram is not None: root.addHandler(ram) else: # If we add no handler, we shouldn't process non visible logs at all # # disable blocks the current level (while setHandler shows the current # level), so -1 to avoid blocking handled messages. logging.disable(numeric_level - 1) global _log_inited, _args _args = args root.setLevel(logging.NOTSET) logging.captureWarnings(True) _init_py_warnings() QtCore.qInstallMessageHandler(qt_message_handler) _log_inited = True