diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-07-25 08:26:13 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-07-25 08:26:13 +0000 |
commit | 5b125fd1420ee7aebfccf7bc4106883c4f3b02ad (patch) | |
tree | 73abde79174c7bab4733378f46967c97519ffb23 | |
parent | ddb4eccb75af9838b22436fa4ce71a38e9d24591 (diff) | |
download | portage-5b125fd1420ee7aebfccf7bc4106883c4f3b02ad.tar.gz portage-5b125fd1420ee7aebfccf7bc4106883c4f3b02ad.tar.bz2 portage-5b125fd1420ee7aebfccf7bc4106883c4f3b02ad.zip |
Set O_NONBLOCK just for read calls (uses fewer fcntl calls).
svn path=/main/trunk/; revision=7393
-rw-r--r-- | pym/portage/__init__.py | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index d7af652c6..54ef005a4 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2484,48 +2484,37 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero owtd = [] ewtd = [] import array, fcntl, select - # Use non-blocking mode to prevent read - # calls from blocking indefinitely. fd_flags = {} for f in iwtd: fd_flags[f] = fcntl.fcntl(f.fileno(), fcntl.F_GETFL) - fcntl.fcntl(f.fileno(), fcntl.F_SETFL, - fd_flags[f] | os.O_NONBLOCK) buffsize = 65536 eof = False while not eof: events = select.select(iwtd, owtd, ewtd) for f in events[0]: + # Use non-blocking mode to prevent read + # calls from blocking indefinitely. + fcntl.fcntl(f.fileno(), fcntl.F_SETFL, + fd_flags[f] | os.O_NONBLOCK) buf = array.array('B') try: buf.fromfile(f, buffsize) except EOFError: pass + fcntl.fcntl(f.fileno(), fcntl.F_SETFL, fd_flags[f]) if not buf: eof = True break # Use blocking mode for writes since we'd rather block than # trigger a EWOULDBLOCK error. if f is stdin_file: - fcntl.fcntl(master_file.fileno(), - fcntl.F_SETFL, fd_flags[f]) buf.tofile(master_file) master_file.flush() - fcntl.fcntl(master_file.fileno(), - fcntl.F_SETFL, fd_flags[f] | os.O_NONBLOCK) else: - # stdout usually shares the O_NONBLOCK flag with stdin - fcntl.fcntl(stdin_file.fileno(), - fcntl.F_SETFL, fd_flags[f]) buf.tofile(stdout_file) stdout_file.flush() - fcntl.fcntl(stdin_file.fileno(), - fcntl.F_SETFL, fd_flags[f] | os.O_NONBLOCK) buf.tofile(log_file) log_file.flush() - # Restore them to blocking mode. - for f in iwtd: - fcntl.fcntl(f.fileno(), fcntl.F_SETFL, fd_flags[f]) log_file.close() stdin_file.close() stdout_file.close() |