gh-153291: Fix data race in readline.get_completer() and get_pre_input_hook() by harjothkhara · Pull Request #153362 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Lib/test/test_free_threading/test_readline.py
24 changes: 0 additions & 24 deletions Lib/test/test_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import sys
import tempfile
import textwrap
import threading
import unittest
from test import support
from test.support import threading_helper
from test.support import verbose
from test.support.import_helper import import_module
from test.support.os_helper import unlink, temp_dir, TESTFN
Expand Down Expand Up @@ -442,26 +439,5 @@ def my_hook():
self.assertIs(readline.get_pre_input_hook(), my_hook)


@unittest.skipUnless(support.Py_GIL_DISABLED, 'these tests can only possibly fail with GIL disabled')
class FreeThreadingTest(unittest.TestCase):
@threading_helper.reap_threads
@threading_helper.requires_working_threading()
def test_free_threading(self):
def completer_delims(b):
b.wait()
for _ in range(100):
readline.get_completer_delims()
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
readline.get_completer_delims()

count = 40
barrier = threading.Barrier(count)
threads = [threading.Thread(target=completer_delims, args=(barrier,)) for _ in range(count)]

with threading_helper.start_threads(threads):
pass


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix a data race in :func:`readline.get_completer` and
:func:`readline.get_pre_input_hook` on the :term:`free-threaded <free
threading>` build: the getters read the stored hook without the critical
section that the corresponding setters hold.
18 changes: 15 additions & 3 deletions Modules/clinic/readline.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Modules/readline.c
Loading