|
4 | 4 | import signal
|
5 | 5 | import subprocess
|
6 | 6 | import sys
|
| 7 | +import threading |
7 | 8 | import unittest
|
8 | 9 | from functools import partial
|
9 | 10 | from test.support import os_helper, force_not_colorized_test_class
|
10 |
| -from test.support import script_helper |
| 11 | +from test.support import script_helper, threading_helper |
11 | 12 |
|
12 | 13 | from unittest import TestCase
|
13 | 14 | from unittest.mock import MagicMock, call, patch, ANY, Mock
|
@@ -317,23 +318,16 @@ def test_restore_with_invalid_environ_on_macos(self, _os_write):
|
317 | 318 | console.prepare() # needed to call restore()
|
318 | 319 | console.restore() # this should succeed
|
319 | 320 |
|
| 321 | + @threading_helper.reap_threads |
| 322 | + @threading_helper.requires_working_threading() |
320 | 323 | def test_restore_in_thread(self, _os_write):
|
321 |
| - # for gh-139391 |
322 |
| - import threading |
| 324 | + # gh-139391: ensure that console.restore() silently suppresses |
| 325 | + # exceptions when calling signal.signal() from a non-main thread. |
323 | 326 | console = unix_console([])
|
324 | 327 | console.old_sigwinch = signal.SIG_DFL
|
325 |
| - exception_caught = [] |
326 |
| - def thread_target(): |
327 |
| - try: |
328 |
| - console.restore() |
329 |
| - except Exception as e: |
330 |
| - exception_caught.append(e) |
331 |
| - thread = threading.Thread(target=thread_target) |
| 328 | + thread = threading.Thread(target=console.restore) |
332 | 329 | thread.start()
|
333 |
| - thread.join() |
334 |
| - # gh-139391: should not raise any exception when called from non-main thread |
335 |
| - self.assertEqual(len(exception_caught), 0, |
336 |
| - "restore() should not raise any exception in non-main thread") |
| 330 | + thread.join() # this should not raise |
337 | 331 |
|
338 | 332 |
|
339 | 333 | @unittest.skipIf(sys.platform == "win32", "No Unix console on Windows")
|
|
0 commit comments