summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-05-15 03:05:36 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-05-15 03:05:36 (GMT)
commit3712686956b2bf9e3c98f394a1a27f99fafdbaa8 (patch)
tree6022a735938996710b4665f7b1650718a3a2cb94 /Lib
parentf0dbf7a6abc821c77e912deae81e3a27cf334c54 (diff)
downloadcpython-3712686956b2bf9e3c98f394a1a27f99fafdbaa8.zip
cpython-3712686956b2bf9e3c98f394a1a27f99fafdbaa8.tar.gz
cpython-3712686956b2bf9e3c98f394a1a27f99fafdbaa8.tar.bz2
Issue #26870: Close pty master in case of exception
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_readline.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py
index 84fd119..372b055 100644
--- a/Lib/test/test_readline.py
+++ b/Lib/test/test_readline.py
@@ -1,6 +1,7 @@
"""
Very minimal unittests for parts of the readline module.
"""
+from contextlib import ExitStack
from errno import EIO
import os
import selectors
@@ -123,7 +124,10 @@ def run_pty(script, input=b"dummy input\r"):
args = (sys.executable, '-c', script)
proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave)
os.close(slave)
- with proc, selectors.DefaultSelector() as sel:
+ with ExitStack() as cleanup:
+ cleanup.enter_context(proc)
+ cleanup.callback(os.close, master)
+ sel = cleanup.enter_context(selectors.DefaultSelector())
sel.register(master, selectors.EVENT_READ | selectors.EVENT_WRITE)
os.set_blocking(master, False)
while True:
@@ -137,7 +141,6 @@ def run_pty(script, input=b"dummy input\r"):
raise
chunk = b""
if not chunk:
- os.close(master)
return output
output.extend(chunk)
if events & selectors.EVENT_WRITE: