Skip to content

Commit 991ca84

Browse files
committed
pythongh-126895: fix readline module in free-threaded build
1 parent c5abded commit 991ca84

File tree

3 files changed

+213
-35
lines changed

3 files changed

+213
-35
lines changed

Lib/test/test_readline.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import sys
77
import tempfile
88
import textwrap
9+
import threading
910
import unittest
11+
from test import support
12+
from test.support import threading_helper
1013
from test.support import verbose
1114
from test.support.import_helper import import_module
1215
from test.support.os_helper import unlink, temp_dir, TESTFN
@@ -403,5 +406,62 @@ def test_write_read_limited_history(self):
403406
# See TestHistoryManipulation for the full test.
404407

405408

409+
@unittest.skipUnless(support.Py_GIL_DISABLED, 'these tests can only possibly fail with GIL disabled')
410+
class FreeThreadingTest(unittest.TestCase):
411+
def check(self, funcs, *args):
412+
barrier = threading.Barrier(len(funcs))
413+
threads = []
414+
415+
for func in funcs:
416+
thread = threading.Thread(target=func, args=(barrier, *args))
417+
418+
threads.append(thread)
419+
420+
with threading_helper.start_threads(threads):
421+
pass
422+
423+
@threading_helper.reap_threads
424+
@threading_helper.requires_working_threading()
425+
def test_free_threading(self):
426+
def completer_delims(b):
427+
b.wait()
428+
for _ in range(100):
429+
readline.get_completer_delims()
430+
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
431+
readline.set_completer_delims(' \t\n`@#%^&*()=+[{]}\\|;:\'",<>?')
432+
readline.get_completer_delims()
433+
434+
self.check([completer_delims] * 100)
435+
436+
@threading_helper.reap_threads
437+
@threading_helper.requires_working_threading()
438+
def test_free_threading_doctest_difflib(self):
439+
import doctest, difflib
440+
441+
preserve_stdout = sys.stdout
442+
COUNT = 40
443+
funcs = []
444+
results = [False] * COUNT
445+
446+
for i in range(COUNT):
447+
def func(b, i=i):
448+
try:
449+
doctest.testmod(difflib)
450+
except RecursionError:
451+
results[i] = True
452+
except Exception:
453+
pass
454+
else:
455+
results[i] = True
456+
457+
funcs.append(func)
458+
459+
self.check(funcs)
460+
461+
sys.stdout = preserve_stdout
462+
463+
self.assertTrue(all(results))
464+
465+
406466
if __name__ == "__main__":
407467
unittest.main()

Modules/clinic/readline.c.h

Lines changed: 109 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)