disabled
 ?÷     a time will be reading from the file object. This matters because
    # if a timeout exception is raised, the user may call back into communicate() to
    # get the output (usually after killing the process; see run()). We must not
    # lose output in that case (Python 3 specifically documents that raising a timeout
    # doesn't lose output). Also, attempting to read from a pipe while it's already
    # being read from results in `RuntimeError: reentrant call in io.BufferedReader`;
    # the same thing happens if you attempt to close() it while that's in progress.
    __slots__ = (
        'stdin',
        'stdout',
        'stderr',
        '_all_greenlets',
    )

    def __init__(self, popen, input_data):
        self.stdin = self.stdout = self.stderr = None
        if popen.stdin: # Even if no data, we need to close
            self.stdin = spawn(self._write_and_close, popen.stdin, input_data)

        # If the timeout parameter is used, and the caller calls back after
        # getting a TimeoutExpired exception, we can wind up with multiple
        # greenlets trying to run and read from and close stdout/stderr.
        # That's bad because it can lead to 'RuntimeError: reentrant call in io.BufferedReader'.
        # We can't just kill the previous greenlets when a timeout happens,
        # though, because we risk losing the output collected by that greenlet
        # (and Python 3, where timeout is an official parameter, explicitly says
        # that no output should be lost in the event of a timeout.) Instead, we're
        # watching for the exception and ignoring it. It's not elegant,
        # but it works
        if popen.stdout:
            self.stdout = spawn(self._read_and_close, popen.stdout)

        if popen.stderr:
            self.stderr = spawn(self._read_and_close, popen.stderr)

        all_greenlets = []
        for g in self.stdin, self.stdout, self.stderr:
            if g is not None:
                all_greenlets.append(g)
        self._all_greenlets = tuple(all_greenlets)

    def __iter__(self):
        return iter(self._all_greenlets)

    def __bool__(self):
        return bool(self._all_greenlets)

    __nonzero__ = __bool__

    def __len__(self):
        return len(self._all_greenlets)

    @staticmethod
    def _write_and_close(fobj, data):
        try:
            if data:
                fobj.write(data)
                if hasattr(fobj, 'flush'):
                    # 3.6 started expecting flush to be called.
                    fobj.flush()
        except (OSError, IOError, BrokenPipeError) as ex:
            # Test cases from the stdlib can raise BrokenPipeError
            # without setting an errno value. This matters because
            # Python 2 doesn't have a BrokenPipeError.
            if isinstance(ex, BrokenPipeError) and ex.errno is None:
                ex.errno = errno.EPIPE
            if ex.errno not in (errno.EPIPE, errno.EINVAL):
                raise
        finally:
            try:
                fobj.close()
            except EnvironmentError:
                pass

    @staticmethod
    def _read_and_close(fobj):
        try:
            return fobj.read()
        finally:
            try:
                fobj.close()
            except EnvironmentError:
                pass


class Popen(object):
    """
    The underlying process creation and management in this module is
    handled by the Popen class. It offers a lot of flexibility so that
    developers are able to handle the less common cases not covered by
    the convenience functions.

    .. seealso:: :class:`subprocess.Popen`
       This class should have the same interface as the standard library class.

    .. caution::

       The default values of some arguments, notably ``buffering``, differ
       between Python 2 and Python 3. For the most consistent behaviour across
       versions, it's best to explicitly pass the desired values.

    .. caution::

       On Python 2, the ``read`` method of the ``stdout`` and ``stderr`` attributes
       will not be buffered unless buf