mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-135124: Change stdout errors in regrtest worker process (GH-135138) (#135168)
gh-135124: Change stdout errors in regrtest worker process (GH-135138)
Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.
Move the code from the Regrtest class to setup_process().
Call setup_process() earlier, before displaying regrtest headers.
(cherry picked from commit 3d396ab759)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
07921d4169
commit
285c69ea38
3 changed files with 51 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import faulthandler
|
||||
import gc
|
||||
import io
|
||||
import os
|
||||
import random
|
||||
import signal
|
||||
|
|
@ -52,6 +53,14 @@ def setup_process() -> None:
|
|||
|
||||
support.record_original_stdout(sys.stdout)
|
||||
|
||||
# Set sys.stdout encoder error handler to backslashreplace,
|
||||
# similar to sys.stderr error handler, to avoid UnicodeEncodeError
|
||||
# when printing a traceback or any other non-encodable character.
|
||||
#
|
||||
# Use an assertion to fix mypy error.
|
||||
assert isinstance(sys.stdout, io.TextIOWrapper)
|
||||
sys.stdout.reconfigure(errors="backslashreplace")
|
||||
|
||||
# Some times __path__ and __file__ are not absolute (e.g. while running from
|
||||
# Lib/) and, if we change the CWD to run the tests in a temporary dir, some
|
||||
# imports might fail. This affects only the modules imported before os.chdir().
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue