mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
prevent writing to stderr from messing up the exception state (closes #14474)
This commit is contained in:
parent
b6af60c2a9
commit
e900096dc4
3 changed files with 30 additions and 0 deletions
|
@ -128,6 +128,30 @@ class ThreadRunningTests(BasicThreadTest):
|
|||
time.sleep(0.01)
|
||||
self.assertEqual(thread._count(), orig)
|
||||
|
||||
def test_save_exception_state_on_error(self):
|
||||
# See issue #14474
|
||||
def task():
|
||||
started.release()
|
||||
sys.stderr = stderr
|
||||
raise SyntaxError
|
||||
def mywrite(self, *args):
|
||||
try:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
pass
|
||||
real_write(self, *args)
|
||||
c = thread._count()
|
||||
started = thread.allocate_lock()
|
||||
with support.captured_output("stderr") as stderr:
|
||||
real_write = stderr.write
|
||||
stderr.write = mywrite
|
||||
started.acquire()
|
||||
thread.start_new_thread(task, ())
|
||||
started.acquire()
|
||||
while thread._count() > c:
|
||||
pass
|
||||
self.assertIn("Traceback", stderr.getvalue())
|
||||
|
||||
|
||||
class Barrier:
|
||||
def __init__(self, num_threads):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue