|
12 | 12 | import weakref |
13 | 13 | import os |
14 | 14 | from test.script_helper import assert_python_ok, assert_python_failure |
| 15 | +import subprocess |
15 | 16 |
|
16 | 17 | from test import lock_tests |
17 | 18 |
|
@@ -703,6 +704,37 @@ def test_releasing_unacquired_lock(self): |
703 | 704 | lock = threading.Lock() |
704 | 705 | self.assertRaises(RuntimeError, lock.release) |
705 | 706 |
|
| 707 | + @unittest.skipUnless(sys.platform == 'darwin', 'test macosx problem') |
| 708 | + def test_recursion_limit(self): |
| 709 | + # Issue 9670 |
| 710 | + # test that excessive recursion within a non-main thread causes |
| 711 | + # an exception rather than crashing the interpreter on platforms |
| 712 | + # like Mac OS X or FreeBSD which have small default stack sizes |
| 713 | + # for threads |
| 714 | + script = """if True: |
| 715 | + import threading |
| 716 | +
|
| 717 | + def recurse(): |
| 718 | + return recurse() |
| 719 | +
|
| 720 | + def outer(): |
| 721 | + try: |
| 722 | + recurse() |
| 723 | + except RuntimeError: |
| 724 | + pass |
| 725 | +
|
| 726 | + w = threading.Thread(target=outer) |
| 727 | + w.start() |
| 728 | + w.join() |
| 729 | + print('end of main thread') |
| 730 | + """ |
| 731 | + expected_output = "end of main thread\n" |
| 732 | + p = subprocess.Popen([sys.executable, "-c", script], |
| 733 | + stdout=subprocess.PIPE) |
| 734 | + stdout, stderr = p.communicate() |
| 735 | + data = stdout.decode().replace('\r', '') |
| 736 | + self.assertEqual(p.returncode, 0, "Unexpected error") |
| 737 | + self.assertEqual(data, expected_output) |
706 | 738 |
|
707 | 739 | class LockTests(lock_tests.LockTests): |
708 | 740 | locktype = staticmethod(threading.Lock) |
|
0 commit comments