portage.util._async.PipeLogger module

class portage.util._async.PipeLogger.PipeLogger(**kwargs)

Bases: _emerge.AbstractPollTask.AbstractPollTask

This can be used for logging output of a child process, optionally outputing to log_file_path and/or stdout_fd. It can also monitor for EOF on input_fd, which may be used to detect termination of a child process. If log_file_path ends with ‘.gz’ then the log file is written with compression.


Subclasses call this method in order to invoke exit listeners when self.returncode is set. Subclasses may override this method in order to perform cleanup. The default implementation for this method simply calls self.wait(), which will immediately raise an InvalidStateError if the event loop is running and self.returncode is None.

_bufsize = 4096

Subclasses should implement this, as a template method to be called by AsynchronousTask.cancel().

_cancelled_returncode = -2
async _io_loop(input_file)

NOTE: array.fromfile() is used here only for testing purposes, because it has bugs in all known versions of Python (including Python 2.7 and Python 3.2). See PipeReaderArrayTestCase.

A benchmark that copies bytes from /dev/zero to /dev/null shows that arrays give a 15% performance improvement for Python 2.7.14. However, arrays significantly decrease performance for Python 3.


Read self._bufsize into a string of bytes, handling EAGAIN and EIO. This will only call os.read() once, so the caller should call this method in a loop until either None or an empty string of bytes is returned. An empty string of bytes indicates EOF. None indicates EAGAIN.

NOTE: os.read() will be called regardless of the event flags,

since otherwise data may be lost (see bug #531724).


fd (int) – file descriptor (non-blocking mode required)

Return type

bytes or None


A string of bytes, or None


Call this method after the task completes, just before returning the returncode from wait() or poll(). This hook is used to trigger exit listeners when the returncode first becomes available.


If cancelled, set returncode if necessary and return True. Otherwise, return False.


The function will be called with one argument, a reference to self.


The function will be called with one argument, a reference to self.


Wait for returncode asynchronously. Notification is available via the add_done_callback method of the returned Future instance.


Future, result is self.returncode


Cancel the task, but do not wait for exit status. If asynchronous exit notification is desired, then use addExitListener to add a listener before calling this method. NOTE: Synchronous waiting for status is not supported, since it would be vulnerable to hitting the recursion limit when a large number of tasks need to be terminated simultaneously, like in bug #402335.


Create a new instance and copy all attributes defined from __slots__ (including those from inherited classes).


Start an asynchronous task and then return as soon as possible.


Wait for the returncode attribute to become ready, and return it. If the returncode is not ready and the event loop is already running, then the async_wait() method should be used instead of wait(), because wait() will raise asyncio.InvalidStateError in this case.

Return type



the value of self.returncode