summaryrefslogtreecommitdiffstats
path: root/Lib/pty.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2012-02-16 08:29:12 (GMT)
committerGregory P. Smith <greg@krypto.org>2012-02-16 08:29:12 (GMT)
commit05f5953ab4854218205e4c0f04a26a9dd5b09a9c (patch)
tree3683b2cf98bd9613066f4bf7fad73675fb41293d /Lib/pty.py
parent5c724a804af2ed06977af0b4e997692640b5accb (diff)
downloadcpython-05f5953ab4854218205e4c0f04a26a9dd5b09a9c.zip
cpython-05f5953ab4854218205e4c0f04a26a9dd5b09a9c.tar.gz
cpython-05f5953ab4854218205e4c0f04a26a9dd5b09a9c.tar.bz2
Issue #2489: Fix bug in _copy loop that could consume 100% cpu on EOF.
Diffstat (limited to 'Lib/pty.py')
-rw-r--r--Lib/pty.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/pty.py b/Lib/pty.py
index 810ebd8..3ccf619 100644
--- a/Lib/pty.py
+++ b/Lib/pty.py
@@ -142,15 +142,21 @@ def _copy(master_fd, master_read=_read, stdin_read=_read):
Copies
pty master -> standard output (master_read)
standard input -> pty master (stdin_read)"""
- while 1:
- rfds, wfds, xfds = select(
- [master_fd, STDIN_FILENO], [], [])
+ fds = [master_fd, STDIN_FILENO]
+ while True:
+ rfds, wfds, xfds = select(fds, [], [])
if master_fd in rfds:
data = master_read(master_fd)
- os.write(STDOUT_FILENO, data)
+ if not data: # Reached EOF.
+ fds.remove(master_fd)
+ else:
+ os.write(STDOUT_FILENO, data)
if STDIN_FILENO in rfds:
data = stdin_read(STDIN_FILENO)
- _writen(master_fd, data)
+ if not data:
+ fds.remove(STDIN_FILENO)
+ else:
+ _writen(master_fd, data)
def spawn(argv, master_read=_read, stdin_read=_read):
"""Create a spawned process."""