diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-12-15 18:02:32 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-12-15 18:02:32 -0800 |
commit | 30d2d0a9db486c5a70848ad5d27b37a3ec48f271 (patch) | |
tree | 41a00a4003a65dce79b426bf444ea16d0494367c /pym/_emerge/AbstractPollTask.py | |
parent | 915348ce34fc499ac295b8f0ffee9f0829803542 (diff) | |
download | portage-30d2d0a9db486c5a70848ad5d27b37a3ec48f271.tar.gz portage-30d2d0a9db486c5a70848ad5d27b37a3ec48f271.tar.bz2 portage-30d2d0a9db486c5a70848ad5d27b37a3ec48f271.zip |
SpawnProcess: work around array.fromfile() bugs
When I extended test_poll to test SpawnProcess array.fromfile() usage,
it exposed bugs in array.fromfile() that I couldn't find a way to
handle. So, use os.read() instead.
Diffstat (limited to 'pym/_emerge/AbstractPollTask.py')
-rw-r--r-- | pym/_emerge/AbstractPollTask.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index f7f3a9526..ea13587bc 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -2,7 +2,9 @@ # Distributed under the terms of the GNU General Public License v2 import array +import errno import logging +import os from portage.util import writemsg_level from _emerge.AsynchronousTask import AsynchronousTask @@ -20,7 +22,7 @@ class AbstractPollTask(AsynchronousTask): def isAlive(self): return bool(self._registered) - def _read_buf(self, f, event): + def _read_buf(self, fd, event): """ | POLLIN | RETURN | BIT | VALUE @@ -32,13 +34,26 @@ class AbstractPollTask(AsynchronousTask): | --------------------------------------------------- | 0 | None """ + # NOTE: array.fromfile() is no longer used here because it has + # bugs in all known versions of Python (including Python 2.7 + # and Python 3.2). buf = None if event & PollConstants.POLLIN: buf = array.array('B') try: - buf.fromfile(f, self._bufsize) - except (EOFError, IOError): - pass + # Python >=3.2 + frombytes = buf.frombytes + except AttributeError: + frombytes = buf.fromstring + try: + frombytes(os.read(fd, self._bufsize)) + except OSError as e: + # EIO happens with pty on Linux after the + # slave end of the pty has been closed. + if e.errno not in (errno.EAGAIN, errno.EIO): + raise + buf = None + return buf def _unregister(self): |