Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 26 Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,32 @@ def test_raise_exception(self):
3,
name)

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_raise_nonfatal_exception(self):
# These exceptions are not strictly errors. Letting
# faulthandler display the traceback when they are
# raised is likely to result in noise. However, they
# may still terminate the process if there is no
# handler installed for them (which there typically
# is, e.g. for debug messages).
for exc in (
0x00000000,
0x34567890,
0x40000000,
0x40001000,
0x70000000,
0x7FFFFFFF,
):
output, exitcode = self.get_output(f"""
import faulthandler
faulthandler.enable()
faulthandler._raise_exception(0x{exc:x})
"""
)
self.assertEqual(output, [])
# Actual exception code has bit 4 cleared
self.assertEqual(exitcode, exc & ~0x10000000)

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_disable_windows_exc_handler(self):
code = dedent("""
Expand Down
3 changes: 3 additions & 0 deletions 3 Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ Extension Modules
Library
-------

- bpo-30557: faulthandler now correctly filters and displays exception codes
on Windows

- bpo-30526: Add TextIOWrapper.reconfigure() and a TextIOWrapper.write_through
attribute.

Expand Down
8 changes: 4 additions & 4 deletions 8 Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
DWORD code = exc_info->ExceptionRecord->ExceptionCode;
DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;

/* only log fatal exceptions */
if (flags & EXCEPTION_NONCONTINUABLE) {
/* bpo-30557: only log fatal exceptions */
if (!(code & 0x80000000)) {
/* call the next exception handler */
return EXCEPTION_CONTINUE_SEARCH;
}
Expand All @@ -391,8 +391,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
case EXCEPTION_IN_PAGE_ERROR: PUTS(fd, "page error"); break;
case EXCEPTION_STACK_OVERFLOW: PUTS(fd, "stack overflow"); break;
default:
PUTS(fd, "code ");
_Py_DumpDecimal(fd, code);
PUTS(fd, "code 0x");
_Py_DumpHexadecimal(fd, code, 8);
}
PUTS(fd, "\n\n");

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.