本文整理匯總了Python中faulthandler.enable方法的典型用法代碼示例。如果您正苦於以下問題:Python faulthandler.enable方法的具體用法?Python faulthandler.enable怎麽用?Python faulthandler.enable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類faulthandler
的用法示例。
在下文中一共展示了faulthandler.enable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _check_modules
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def _check_modules(modules):
"""Make sure the given modules are available."""
from qutebrowser.utils import log
for name, text in modules.items():
try:
# https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
# pylint: disable=bad-continuation
with log.ignore_py_warnings(
category=DeprecationWarning,
message=r'invalid escape sequence'
), log.ignore_py_warnings(
category=ImportWarning,
message=r'Not importing directory .*: missing __init__'
), log.ignore_py_warnings(
category=DeprecationWarning,
message=r'the imp module is deprecated',
):
# pylint: enable=bad-continuation
importlib.import_module(name)
except ImportError as e:
_die(text, e)
示例2: configure_pyqt
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def configure_pyqt():
"""Remove the PyQt input hook and enable overflow checking.
Doing this means we can't use the interactive shell anymore (which we don't
anyways), but we can use pdb instead.
"""
from PyQt5 import QtCore
QtCore.pyqtRemoveInputHook()
try:
QtCore.pyqt5_enable_new_onexit_scheme( # type: ignore[attr-defined]
True)
except AttributeError:
# Added in PyQt 5.13 somewhere, going to be the default in 5.14
pass
from qutebrowser.qt import sip
try:
# Added in sip 4.19.4
sip.enableoverflowchecking(True) # type: ignore[attr-defined]
except AttributeError:
pass
示例3: destroy_crashlogfile
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
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!")
示例4: enableFaulthandler
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
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
示例5: get_name
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def get_name(request):
import faulthandler
faulthandler.enable()
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/thanks/')
# if a GET (or any other method) we'll create a blank form
else:
form = NameForm(data={'your_name': 'unknown name'})
return render(request, 'my_app/name.html', {'form': form})
示例6: test_is_enabled
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
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
示例7: main
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def main():
faulthandler.enable()
parser = ArgumentParser()
subparsers = parser.add_subparsers(help='DeclaraCAD subcommands')
viewer = subparsers.add_parser("view", help="View the given file")
viewer.set_defaults(func=launch_viewer)
viewer.add_argument("file", help="File to view")
viewer.add_argument("-w", "--watch", action='store_true',
help="Watch for file changes and autoreload")
viewer.add_argument("-f", "--frameless", action='store_true',
help="Frameless viewer")
exporter = subparsers.add_parser("export", help="Export the given file")
exporter.set_defaults(func=launch_exporter)
exporter.add_argument("options", help="File to export or json string of "
"ExportOption parameters")
args = parser.parse_args()
# Start the app
launcher = getattr(args, 'func', launch_workbench)
launcher(args)
示例8: _run_init
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def _run_init(
argv,
flags_parser,
):
"""Does one-time initialization and re-parses flags on rerun."""
if _run_init.done:
return flags_parser(argv)
command_name.make_process_name_useful()
# Set up absl logging handler.
logging.use_absl_handler()
args = _register_and_parse_flags_with_usage(
argv=argv,
flags_parser=flags_parser,
)
if faulthandler:
try:
faulthandler.enable()
except Exception: # pylint: disable=broad-except
# Some tests verify stderr output very closely, so don't print anything.
# Disabled faulthandler is a low-impact error.
pass
_run_init.done = True
return args
示例9: _init_diagnostic_logging
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def _init_diagnostic_logging(self) -> None:
logFormatter = logging.Formatter("%(levelname)s: %(message)s")
root_logger = logging.getLogger()
log_file = os.path.join(THONNY_USER_DIR, "frontend.log")
file_handler = logging.FileHandler(log_file, encoding="UTF-8", mode="w")
file_handler.setFormatter(logFormatter)
file_handler.setLevel(self._get_logging_level())
root_logger.addHandler(file_handler)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(logFormatter)
console_handler.setLevel(self._get_logging_level())
root_logger.addHandler(console_handler)
root_logger.setLevel(self._get_logging_level())
import faulthandler
fault_out = open(os.path.join(THONNY_USER_DIR, "frontend_faults.log"), mode="w")
faulthandler.enable(fault_out)
示例10: common_setup
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def common_setup(enable_affinity=True, _init_logging=True):
save_pid('controller')
ansible_mitogen.logging.set_process_name('top')
if _init_logging:
ansible_mitogen.logging.setup()
if enable_affinity:
ansible_mitogen.affinity.policy.assign_controller()
mitogen.utils.setup_gil()
if faulthandler is not None:
faulthandler.enable()
MuxProcess.profiling = getenv_int('MITOGEN_PROFILING') > 0
if MuxProcess.profiling:
mitogen.core.enable_profiling()
MuxProcess.cls_original_env = dict(os.environ)
increase_open_file_limit()
示例11: main
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def main():
logging.basicConfig(level='DEBUG',stream=sys.stdout,format='%(asctime)s %(levelname)-8s %(name)-15s %(message)s')
try:
import faulthandler
faulthandler.enable()
except ImportError:
pass
with enaml.imports():
from view import Main
app = QtApplication()
profiler = cProfile.Profile()
view = Main()
view.show()
# Start the application event loop
profiler.enable()
app.start()
profiler.disable()
profiler.print_stats('tottime')
示例12: init_faulthandler
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def init_faulthandler(fileobj=sys.__stderr__):
"""Enable faulthandler module if available.
This print a nice traceback on segfaults.
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".
Args:
fobj: An opened file object to write the traceback to.
"""
if fileobj is None:
# When run with pythonw.exe, sys.__stderr__ can be None:
# https://docs.python.org/3/library/sys.html#sys.__stderr__
# If we'd enable faulthandler in that case, we just get a weird
# exception, so we don't enable faulthandler if we have no stdout.
#
# Later when we have our data dir available we re-enable faulthandler
# to write to a file so we can display a crash to the user at the next
# start.
return
faulthandler.enable(fileobj)
if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and
sys.stderr is not None):
# If available, we also want a traceback on SIGUSR1.
# pylint: disable=no-member,useless-suppression
faulthandler.register(signal.SIGUSR1)
# pylint: enable=no-member,useless-suppression
示例13: activate
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
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
示例14: install_debugging_signal_handler
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def install_debugging_signal_handler():
import faulthandler
faulthandler.enable()
示例15: pytest_configure
# 需要導入模塊: import faulthandler [as 別名]
# 或者: from faulthandler import enable [as 別名]
def pytest_configure(config):
import faulthandler
# avoid trying to dup sys.stderr if faulthandler is already enabled
if faulthandler.is_enabled():
return
stderr_fd_copy = os.dup(_get_stderr_fileno())
config.fault_handler_stderr = os.fdopen(stderr_fd_copy, "w")
faulthandler.enable(file=config.fault_handler_stderr)