本文整理汇总了Python中faulthandler._sigsegv方法的典型用法代码示例。如果您正苦于以下问题:Python faulthandler._sigsegv方法的具体用法?Python faulthandler._sigsegv怎么用?Python faulthandler._sigsegv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faulthandler
的用法示例。
在下文中一共展示了faulthandler._sigsegv方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sigsegv
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_sigsegv(self):
self.check_fatal_error("""
import faulthandler
faulthandler.enable()
faulthandler._sigsegv()
""",
3,
'Segmentation fault')
示例2: test_gil_released
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_gil_released(self):
self.check_fatal_error("""
import faulthandler
faulthandler.enable()
faulthandler._sigsegv(True)
""",
3,
'Segmentation fault')
示例3: test_enable_file
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_enable_file(self):
with temporary_filename() as filename:
self.check_fatal_error("""
import faulthandler
output = open({filename}, 'wb')
faulthandler.enable(output)
faulthandler._sigsegv()
""".format(filename=repr(filename)),
4,
'Segmentation fault',
filename=filename)
示例4: test_enable_fd
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_enable_fd(self):
with tempfile.TemporaryFile('wb+') as fp:
fd = fp.fileno()
self.check_fatal_error("""
import faulthandler
import sys
faulthandler.enable(%s)
faulthandler._sigsegv()
""" % fd,
4,
'Segmentation fault',
fd=fd)
示例5: test_enable_single_thread
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_enable_single_thread(self):
self.check_fatal_error("""
import faulthandler
faulthandler.enable(all_threads=False)
faulthandler._sigsegv()
""",
3,
'Segmentation fault',
all_threads=False)
示例6: test_disable
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
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)
示例7: _wait_and_crash
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def _wait_and_crash(cls):
_executor_mixin._test_event.wait()
faulthandler._sigsegv()
示例8: crash
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def crash():
"""Induces a segfault"""
import faulthandler
faulthandler._sigsegv()
示例9: test_crashed
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_crashed(self):
# Any code which causes a crash
code = 'import faulthandler; faulthandler._sigsegv()'
crash_test = self.create_test(name="crash", code=code)
ok_test = self.create_test(name="ok")
tests = [crash_test, ok_test]
output = self.run_tests("-j2", *tests, exitcode=2)
self.check_executed_tests(output, tests, failed=crash_test,
randomize=True)
示例10: test_child_terminated_in_stopped_state
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def test_child_terminated_in_stopped_state(self):
"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
libc_name = ctypes.util.find_library('c')
libc = ctypes.CDLL(libc_name)
if not hasattr(libc, 'ptrace'):
raise unittest.SkipTest('ptrace() required')
code = textwrap.dedent("""
import ctypes
import faulthandler
from test.support import SuppressCrashReport
libc = ctypes.CDLL({libc_name!r})
libc.ptrace({PTRACE_TRACEME}, 0, 0)
""".format(libc_name=libc_name, PTRACE_TRACEME=PTRACE_TRACEME))
child = subprocess.Popen([sys.executable, '-c', code])
if child.wait() != 0:
raise unittest.SkipTest('ptrace() failed - unable to test')
code += textwrap.dedent("""
with SuppressCrashReport():
# Crash the process
faulthandler._sigsegv()
""")
child = subprocess.Popen([sys.executable, '-c', code])
try:
returncode = child.wait()
except:
child.kill() # Clean up the hung stopped process.
raise
self.assertNotEqual(0, returncode)
self.assertLess(returncode, 0) # signal death, likely SIGSEGV.
示例11: _crash
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def _crash(delay=None):
"""Induces a segfault."""
if delay:
time.sleep(delay)
import faulthandler
faulthandler.disable()
faulthandler._sigsegv()
示例12: real_main
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import _sigsegv [as 别名]
def real_main(argv):
"""The main function."""
if os.environ.get('APP_TEST_PRINT_ARGV', False):
sys.stdout.write('argv: {}\n'.format(' '.join(argv)))
if FLAGS.raise_exception:
raise MyException
if FLAGS.raise_usage_error:
if FLAGS.usage_error_exitcode is not None:
raise app.UsageError('Error!', FLAGS.usage_error_exitcode)
else:
raise app.UsageError('Error!')
if FLAGS.faulthandler_sigsegv:
faulthandler._sigsegv() # pylint: disable=protected-access
sys.exit(1) # Should not reach here.
if FLAGS.print_init_callbacks:
app.call_after_init(lambda: _callback_results.append('during real_main'))
for value in _callback_results:
print('callback: {}'.format(value))
sys.exit(0)
# Ensure that we have a random C++ flag in flags.FLAGS; this shows
# us that app.run() did the right thing in conjunction with C++ flags.
helper_type = os.environ['APP_TEST_HELPER_TYPE']
if helper_type == 'clif':
if 'heap_check_before_constructors' in flags.FLAGS:
print('PASS: C++ flag present and helper_type is {}'.format(helper_type))
sys.exit(0)
else:
print('FAILED: C++ flag absent but helper_type is {}'.format(helper_type))
sys.exit(1)
elif helper_type == 'pure_python':
if 'heap_check_before_constructors' in flags.FLAGS:
print('FAILED: C++ flag present but helper_type is pure_python')
sys.exit(1)
else:
print('PASS: C++ flag absent and helper_type is pure_python')
sys.exit(0)
else:
print('Unexpected helper_type "{}"'.format(helper_type))
sys.exit(1)