bpo-45410: Add test.support.flush_std_streams() (GH-28885)

support.print_warning() now flushs sys.stdout.
This commit is contained in:
Victor Stinner 2021-10-11 23:07:21 +02:00 committed by GitHub
parent 47717d1186
commit 1ebd798fdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View file

@ -68,20 +68,13 @@ def print_warning(msg):
orig_unraisablehook = None
def flush_std_streams():
if sys.stdout is not None:
sys.stdout.flush()
if sys.stderr is not None:
sys.stderr.flush()
def regrtest_unraisable_hook(unraisable):
global orig_unraisablehook
support.environment_altered = True
print_warning("Unraisable exception")
old_stderr = sys.stderr
try:
flush_std_streams()
support.flush_std_streams()
sys.stderr = sys.__stderr__
orig_unraisablehook(unraisable)
sys.stderr.flush()
@ -104,7 +97,7 @@ def regrtest_threading_excepthook(args):
print_warning(f"Uncaught thread exception: {args.exc_type.__name__}")
old_stderr = sys.stderr
try:
flush_std_streams()
support.flush_std_streams()
sys.stderr = sys.__stderr__
orig_threading_excepthook(args)
sys.stderr.flush()