mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
bpo-25588: Fix regrtest when run inside IDLE (#3962)
When regrtest in run inside IDLE, sys.stdout and sys.stderr are not TextIOWrapper objects and have no file descriptor associated: sys.stderr.fileno() raises io.UnsupportedOperation. Disable faulthandler and don't replace sys.stdout in that case.
This commit is contained in:
parent
7f58097083
commit
ccef823939
1 changed files with 30 additions and 11 deletions
|
|
@ -14,17 +14,26 @@ from test.libregrtest.refleak import warm_caches
|
||||||
|
|
||||||
|
|
||||||
def setup_tests(ns):
|
def setup_tests(ns):
|
||||||
# Display the Python traceback on fatal errors (e.g. segfault)
|
try:
|
||||||
faulthandler.enable(all_threads=True)
|
stderr_fd = sys.__stderr__.fileno()
|
||||||
|
except (ValueError, AttributeError):
|
||||||
|
# Catch ValueError to catch io.UnsupportedOperation on TextIOBase
|
||||||
|
# and ValueError on a closed stream.
|
||||||
|
#
|
||||||
|
# Catch AttributeError for stderr being None.
|
||||||
|
stderr_fd = None
|
||||||
|
else:
|
||||||
|
# Display the Python traceback on fatal errors (e.g. segfault)
|
||||||
|
faulthandler.enable(all_threads=True, file=stderr_fd)
|
||||||
|
|
||||||
# Display the Python traceback on SIGALRM or SIGUSR1 signal
|
# Display the Python traceback on SIGALRM or SIGUSR1 signal
|
||||||
signals = []
|
signals = []
|
||||||
if hasattr(signal, 'SIGALRM'):
|
if hasattr(signal, 'SIGALRM'):
|
||||||
signals.append(signal.SIGALRM)
|
signals.append(signal.SIGALRM)
|
||||||
if hasattr(signal, 'SIGUSR1'):
|
if hasattr(signal, 'SIGUSR1'):
|
||||||
signals.append(signal.SIGUSR1)
|
signals.append(signal.SIGUSR1)
|
||||||
for signum in signals:
|
for signum in signals:
|
||||||
faulthandler.register(signum, chain=True)
|
faulthandler.register(signum, chain=True, file=stderr_fd)
|
||||||
|
|
||||||
replace_stdout()
|
replace_stdout()
|
||||||
support.record_original_stdout(sys.stdout)
|
support.record_original_stdout(sys.stdout)
|
||||||
|
|
@ -109,7 +118,17 @@ def replace_stdout():
|
||||||
"""Set stdout encoder error handler to backslashreplace (as stderr error
|
"""Set stdout encoder error handler to backslashreplace (as stderr error
|
||||||
handler) to avoid UnicodeEncodeError when printing a traceback"""
|
handler) to avoid UnicodeEncodeError when printing a traceback"""
|
||||||
stdout = sys.stdout
|
stdout = sys.stdout
|
||||||
sys.stdout = open(stdout.fileno(), 'w',
|
try:
|
||||||
|
fd = stdout.fileno()
|
||||||
|
except ValueError:
|
||||||
|
# On IDLE, sys.stdout has no file descriptor and is not a TextIOWrapper
|
||||||
|
# object. Leaving sys.stdout unchanged.
|
||||||
|
#
|
||||||
|
# Catch ValueError to catch io.UnsupportedOperation on TextIOBase
|
||||||
|
# and ValueError on a closed stream.
|
||||||
|
return
|
||||||
|
|
||||||
|
sys.stdout = open(fd, 'w',
|
||||||
encoding=stdout.encoding,
|
encoding=stdout.encoding,
|
||||||
errors="backslashreplace",
|
errors="backslashreplace",
|
||||||
closefd=False,
|
closefd=False,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue