mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] gh-123321: Fix Parser/myreadline.c to prevent a segfault during a multi-threaded race (GH-123323) (#123677)
* gh-123321: Fix Parser/myreadline.c to prevent a segfault during a multi-threaded race (GH-123323)
(cherry picked from commit a4562fedad
)
Co-authored-by: Bar Harel <bharel@barharel.com>
* Remove @requires_gil_enabled for 3.12
---------
Co-authored-by: Bar Harel <bharel@barharel.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
c3a866c915
commit
562ff730f3
3 changed files with 37 additions and 3 deletions
|
@ -12,6 +12,7 @@ from test.support.import_helper import import_module
|
|||
from test.support.os_helper import unlink, temp_dir, TESTFN
|
||||
from test.support.pty_helper import run_pty
|
||||
from test.support.script_helper import assert_python_ok
|
||||
from test.support.threading_helper import requires_working_threading
|
||||
|
||||
# Skip tests if there is no readline module
|
||||
readline = import_module('readline')
|
||||
|
@ -346,6 +347,30 @@ readline.write_history_file(history_file)
|
|||
self.assertEqual(len(lines), history_size)
|
||||
self.assertEqual(lines[-1].strip(), b"last input")
|
||||
|
||||
@requires_working_threading()
|
||||
def test_gh123321_threadsafe(self):
|
||||
"""gh-123321: readline should be thread-safe and not crash"""
|
||||
script = textwrap.dedent(r"""
|
||||
import threading
|
||||
from test.support.threading_helper import join_thread
|
||||
|
||||
def func():
|
||||
input()
|
||||
|
||||
thread1 = threading.Thread(target=func)
|
||||
thread2 = threading.Thread(target=func)
|
||||
thread1.start()
|
||||
thread2.start()
|
||||
join_thread(thread1)
|
||||
join_thread(thread2)
|
||||
print("done")
|
||||
""")
|
||||
|
||||
output = run_pty(script, input=b"input1\rinput2\r")
|
||||
|
||||
self.assertIn(b"done", output)
|
||||
|
||||
|
||||
def test_write_read_limited_history(self):
|
||||
previous_length = readline.get_history_length()
|
||||
self.addCleanup(readline.set_history_length, previous_length)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue