diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-03 16:28:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-03 16:28:18 (GMT) |
commit | 6f7346bb3983cd7a6aa97eeeafffb3cecd5292b8 (patch) | |
tree | b3a394496c408eb13503cc90c1a8bfef294f1a0a /Lib/test | |
parent | 5b8787ef191864cd2313015959bcc3e10711aaff (diff) | |
download | cpython-6f7346bb3983cd7a6aa97eeeafffb3cecd5292b8.zip cpython-6f7346bb3983cd7a6aa97eeeafffb3cecd5292b8.tar.gz cpython-6f7346bb3983cd7a6aa97eeeafffb3cecd5292b8.tar.bz2 |
[3.9] bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20613) (GH-20616)
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)
Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.
Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
these functions.
(cherry picked from commit c353764fd564e401cf47a5d9efab18c72c60014e)
* bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)
my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().
my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.
test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().
Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.
(cherry picked from commit fa7ab6aa0f9a4f695e5525db5a113cd21fa93787)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_repl.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py index 71f192f..563f188 100644 --- a/Lib/test/test_repl.py +++ b/Lib/test/test_repl.py @@ -29,7 +29,9 @@ def spawn_repl(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): # test.support.script_helper. env = kw.setdefault('env', dict(os.environ)) env['TERM'] = 'vt100' - return subprocess.Popen(cmd_line, executable=sys.executable, + return subprocess.Popen(cmd_line, + executable=sys.executable, + text=True, stdin=subprocess.PIPE, stdout=stdout, stderr=stderr, **kw) @@ -49,12 +51,11 @@ class TestInteractiveInterpreter(unittest.TestCase): sys.exit(0) """ user_input = dedent(user_input) - user_input = user_input.encode() p = spawn_repl() with SuppressCrashReport(): p.stdin.write(user_input) output = kill_python(p) - self.assertIn(b'After the exception.', output) + self.assertIn('After the exception.', output) # Exit code 120: Py_FinalizeEx() failed to flush stdout and stderr. self.assertIn(p.returncode, (1, 120)) @@ -86,13 +87,22 @@ class TestInteractiveInterpreter(unittest.TestCase): </test>""" ''' user_input = dedent(user_input) - user_input = user_input.encode() p = spawn_repl() - with SuppressCrashReport(): - p.stdin.write(user_input) + p.stdin.write(user_input) output = kill_python(p) self.assertEqual(p.returncode, 0) + def test_close_stdin(self): + user_input = dedent(''' + import os + print("before close") + os.close(0) + ''') + process = spawn_repl() + output = process.communicate(user_input)[0] + self.assertEqual(process.returncode, 0) + self.assertIn('before close', output) + if __name__ == "__main__": unittest.main() |