def __init__(self, src_file, sync_dst_file, *async_dst_files):
        """Constructor.

        Args:
            src_file: file to read from.
            sync_dst_file: file to write to synchronously when `self.write()` is
                called.
            async_dst_files: files to write to asynchronously
        """
        # save the stack at construction time for debugging later
        self._origin_stack = '\n'.join(traceback.format_stack())
        self.tee_file = None  # convenience for users that want a writable file to put things into the tee
        self._src_file = src_file
        self._sync_dst_file = sync_dst_file
        self._async_dst_files = list(async_dst_files)
        self._write_queues = []
        self._write_threads = []
        for f in async_dst_files:
            q = queue.Queue()

            t = spawn_reader_writer(q.get, functools.partial(self._write, f))
            self._write_queues.append(q)
            self._write_threads.append(t)

        src_fd = self._src_file.fileno()

        def read():
            # We use `os.read()` instead of `file.read()` because `os.read()` will return
            # any non-empty amount of data, blocking only until there is data available to
            # be read. On the other hand, `file.read()` waits until its buffer is full.
            # Since we use this code for console output, `file.read()`'s stuttering output
            # is undesirable.
            try:
                return os.read(src_fd, 1024)
            except OSError:
                # errno 5 on linux; happens with PTYs if the slave is closed. mac os just
                # returns b'' from os.read().
                return six.b('')

        self._read_thread = spawn_reader_writer(read, self._write_to_all)
def __init__ ( self , src_file , sync_dst_file , * async_dst_files ) : self . _origin_stack = '\n' . join ( traceback . format_stack ( ) ) self . tee_file = None self . _src_file = src_file self . _sync_dst_file = sync_dst_file self . _async_dst_files = list ( async_dst_files ) self . _write_queues = [ ] self . _write_threads = [ ] for f in async_dst_files : q = queue . Queue ( ) t = spawn_reader_writer ( q . get , functools . partial ( self . _write , f ) ) self . _write_queues . append ( q ) self . _write_threads . append ( t ) src_fd = self . _src_file . fileno ( ) def read ( ) : try : return os . read ( src_fd , 1024 ) except OSError : return six . b ( '' ) self . _read_thread = spawn_reader_writer ( read , self . _write_to_all )
Constructor.

        Args:
            src_file: file to read from.
            sync_dst_file: file to write to synchronously when `self.write()` is
                called.
            async_dst_files: files to write to asynchronously