<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _system3(cmd, verbose=False):
 """ Execute the given command in a subprocess and wait for it to finish. A thread is run that prints output of the process if verbose is True. """

    
    # Init flag
    interrupted = False
    
    # Create progress
    if verbose > 0:
        progress = Progress()
    
    stdout = []
    def poll_process(p):
        while not interrupted:
            msg = p.stdout.readline().decode()
            if msg:
                stdout.append(msg)
                if 'error' in msg.lower():
                    print(msg.rstrip())
                    if verbose == 1:
                        progress.reset()
                elif verbose > 1:
                    print(msg.rstrip())
                elif verbose == 1:
                    progress.update(msg)
            else:
                break
            time.sleep(0.01)
        #print("thread exit")
    
    # Start process that runs the command
    p = subprocess.Popen(cmd, shell=True, 
                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    
    # Keep reading stdout from it
    # thread.start_new_thread(poll_process, (p,))  Python 2.x
    my_thread = threading.Thread(target=poll_process, args=(p,))
    my_thread.setDaemon(True)
    my_thread.start()
    
    # Wait here
    try:
        while p.poll() is None:
            time.sleep(0.01)
    except KeyboardInterrupt:
        # Set flag
        interrupted = True
        # Kill subprocess
        pid = p.pid
        if hasattr(os,'kill'):
            import signal
            os.kill(pid, signal.SIGKILL)
        elif sys.platform.startswith('win'):
            kernel32 = ctypes.windll.kernel32
            handle = kernel32.OpenProcess(1, 0, pid)
            kernel32.TerminateProcess(handle, 0)
            #os.system("TASKKILL /PID " + str(pid) + " /F")
    
    # All good?
    if interrupted:
        raise RuntimeError('Registration process interrupted by the user.')
    if p.returncode:
        stdout.append(p.stdout.read().decode())
        print(''.join(stdout))
        raise RuntimeError('An error occured during the registration.')