diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-02-16 08:29:12 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-02-16 08:29:12 (GMT) |
commit | 05f5953ab4854218205e4c0f04a26a9dd5b09a9c (patch) | |
tree | 3683b2cf98bd9613066f4bf7fad73675fb41293d /Lib/pty.py | |
parent | 5c724a804af2ed06977af0b4e997692640b5accb (diff) | |
download | cpython-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.py | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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.""" |