'Print text only if we are waiting for input,
and then restore the prompt.'

def print_async(self, text):

    if (self.prompt is not None):
        print ('\n' + text)
        sys.stdout.write(self.prompt)
        sys.stdout.flush()
