class_docstr: Function to capture stdout and stderr streams with timestamps
  
  stackoverflow.com/questions/4984549/merge-and-sync-stdout-and-stderr/5188359
class_docstr_tok: ["Function","to","capture","stdout","and","stderr","streams","with","timestamps","stackoverflow.com\/questions\/4984549\/merge-and-sync-stdout-and-stderr\/5188359"]
docstr: Read from the file descriptor
docstr_tok: ["Read","from","the","file","descriptor"]
code: def _read(self, drain):
      "Read from the file descriptor"
      fd = self.fileno()
      buf = os.read(fd, 4096).decode(self.default_encoding)
      if not buf and not self._buf:
          return None
      if "\n" not in buf:
          if not drain:
              self._buf += buf
              return []
  
      # prepend any data previously read, then split into lines and format
      buf = self._buf + buf
      if "\n" in buf:
          tmp, rest = buf.rsplit("\n", 1)
      else:
          tmp = buf
          rest = None
      self._buf = rest
      now = datetime.datetime.now().isoformat()
      rows = tmp.split("\n")
      self._rows += [(now, f"{self._name} {now}:{r}", r) for r in rows]
      for idx in range(self._lastidx, len(self._rows)):
          iflogger.info(self._rows[idx][1])
      self._lastidx = len(self._rows)
  
file_path: nipype/nipype/utils/subprocess.py
imports: import os
  import sys
  import gc
  import errno
  import select
  import locale
  import datetime
  from pathlib import Path
  from subprocess import Popen, STDOUT, PIPE
  from .filemanip import canonicalize_env, read_stream
  from ..None import logging
label_desc: Use image node_id 4 for calling the Stream obj's underlying member method code with example usage: obj._read(drain) and returns: None, list