def stream_out(p, parse=True):
  """
  Streams the stdout from the given command into python

  Parameters
  ----------
  cmd: str
    the command to execute
  parse: boolean
    to parse the file into json
  """
  res = []
  for line in iter(p.stdout.readline, b''):
    try:
      line = line.decode()
      if parse:
        line = json.loads(line.rstrip())
    except __HOLE__:
      line = pickle.loads(line)
      parse = True
    res.append(line)

  if len(res) == 1:
    res = res[0]
    if type(res) == dict and res.get('error'):
      return on_error(res)

  if not parse:
    res = ''.join(res)

  subprocess.Popen.terminate(p)
  return res
dataset/ETHPy150Open karissa/datpy/datpy.py/stream_out