human
Complete this python program:
def handle_process_output(process, stdout_handler, stderr_handler, finalizer=None, decode_streams=True):
assistant
#Here is the Python program you requested.

    """Registers for notifications to lean that process output is ready to read, and dispatches lines to
    the respective line handlers.
    This function returns once the finalizer returns
    :return: result of finalizer
    :param process: subprocess.Popen instance
    :param stdout_handler: f(stdout_line_string), or None
    :param stderr_handler: f(stderr_line_string), or None
    :param finalizer: f(proc) - wait for proc to finish
    :param decode_streams:
    Assume stdout/stderr streams are binary and decode them before pushing         their contents to handlers.
    Set it to False if `universal_newline == True` (then streams are in text-mode)
    or if decoding must happen later (i.e. for Diffs).
    """
    def pump_stream(cmdline, name, stream, is_decode, handler):
        try:
            for line in stream:
                if handler:
                    if is_decode:
                        line = line.decode(defenc)
                    handler(line)
        except Exception as ex:
            log.error('Pumping    %r    of    cmd(%s)    failed    due    to:    %r', name, cmdline, ex)
            raise CommandError(([('<%s-pump>' % name)] + cmdline), ex)
        finally:
            stream.close()
    cmdline = getattr(process, 'args', '')
    if (not isinstance(cmdline, (tuple, list))):
        cmdline = cmdline.split()
    pumps = []
    if process.stdout:
        pumps.append(('stdout', process.stdout, stdout_handler))
    if process.stderr:
        pumps.append(('stderr', process.stderr, stderr_handler))
    threads = []
    for (name, stream, handler) in pumps:
        t = threading.Thread(target=pump_stream, args=(cmdline, name, stream, decode_streams, handler))
        t.setDaemon(True)
        t.start()
        threads.append(t)
    for t in threads:
        t.join()
    if finalizer:
        return finalizer(process)