mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Issue #26870: Close pty master in case of exception
This commit is contained in:
parent
f0dbf7a6ab
commit
3712686956
1 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Very minimal unittests for parts of the readline module.
|
Very minimal unittests for parts of the readline module.
|
||||||
"""
|
"""
|
||||||
|
from contextlib import ExitStack
|
||||||
from errno import EIO
|
from errno import EIO
|
||||||
import os
|
import os
|
||||||
import selectors
|
import selectors
|
||||||
|
@ -123,7 +124,10 @@ def run_pty(script, input=b"dummy input\r"):
|
||||||
args = (sys.executable, '-c', script)
|
args = (sys.executable, '-c', script)
|
||||||
proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave)
|
proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave)
|
||||||
os.close(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)
|
sel.register(master, selectors.EVENT_READ | selectors.EVENT_WRITE)
|
||||||
os.set_blocking(master, False)
|
os.set_blocking(master, False)
|
||||||
while True:
|
while True:
|
||||||
|
@ -137,7 +141,6 @@ def run_pty(script, input=b"dummy input\r"):
|
||||||
raise
|
raise
|
||||||
chunk = b""
|
chunk = b""
|
||||||
if not chunk:
|
if not chunk:
|
||||||
os.close(master)
|
|
||||||
return output
|
return output
|
||||||
output.extend(chunk)
|
output.extend(chunk)
|
||||||
if events & selectors.EVENT_WRITE:
|
if events & selectors.EVENT_WRITE:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue