bpo-30125: disable faulthandler in ctypes test_SEH (#1237) (#1343)

Disable faulthandler to run test_SEH() of test_ctypes to prevent the
following log with a traceback:

    Windows fatal exception: access violation

Add support.disable_faulthandler() context manager.
(cherry picked from commit a36e939aeb)
This commit is contained in:
Victor Stinner 2017-04-28 16:06:48 +02:00 committed by GitHub
parent cb21f5f3d2
commit e005dd9a6d
2 changed files with 24 additions and 4 deletions

View file

@ -2586,3 +2586,19 @@ def setswitchinterval(interval):
if _is_android_emulator:
interval = minimum_interval
return sys.setswitchinterval(interval)
@contextlib.contextmanager
def disable_faulthandler():
# use sys.__stderr__ instead of sys.stderr, since regrtest replaces
# sys.stderr with a StringIO which has no file descriptor when a test
# is run with -W/--verbose3.
fd = sys.__stderr__.fileno()
is_enabled = faulthandler.is_enabled()
try:
faulthandler.disable()
yield
finally:
if is_enabled:
faulthandler.enable(file=fd, all_threads=True)