human
Complete this python program:
def create_inputhook_qt4(mgr, app=None):
assistant
#Here is the Python code you requested.

    """Create an input hook for running the Qt4 application event loop.
    Parameters
    mgr : an InputHookManager
    app : Qt Application, optional.
    Running application to use.  If not given, we probe Qt for an
    existing application object, and create a new one if none is found.
    Returns
    A pair consisting of a Qt Application (either the one given or the
    one found or created) and a inputhook.
    Notes
    We use a custom input hook instead of PyQt4\s default one, as it
    interacts better with the readline packages (issue #481).
    The inputhook function works in tandem with a \pre_prompt_hook\
    which automatically restores the hook as an inputhook in case the
    latter has been temporarily disabled after having intercepted a
    KeyboardInterrupt.
    """
    if (app is None):
        app = QtCore.QCoreApplication.instance()
        if (app is None):
            app = QtGui.QApplication(['    '])
    ip = InteractiveShell.instance()
    if hasattr(ip, '_inputhook_qt4'):
        return (app, ip._inputhook_qt4)
    def inputhook_qt4():
        "PyOS_InputHook    python    hook    for    Qt4.\n\n                                Process    pending    Qt    events    and    if    there's    no    pending    keyboard\n                                input,    spend    a    short    slice    of    time    (50ms)    running    the    Qt    event\n                                loop.\n\n                                As    a    Python    ctypes    callback    can't    raise    an    exception,    we    catch\n                                the    KeyboardInterrupt    and    temporarily    deactivate    the    hook,\n                                which    will    let    a    *second*    CTRL+C    be    processed    normally    and    go\n                                back    to    a    clean    prompt    line.\n                                "
        try:
            allow_CTRL_C()
            app = QtCore.QCoreApplication.instance()
            if (not app):
                return 0
            app.processEvents(QtCore.QEventLoop.AllEvents, 300)
            if (not stdin_ready()):
                timer = QtCore.QTimer()
                event_loop = QtCore.QEventLoop()
                timer.timeout.connect(event_loop.quit)
                while (not stdin_ready()):
                    timer.start(50)
                    event_loop.exec_()
                    timer.stop()
        except KeyboardInterrupt:
            global got_kbdint, sigint_timer
            ignore_CTRL_C()
            got_kbdint = True
            mgr.clear_inputhook()
            if (os.name == 'posix'):
                pid = os.getpid()
                if (not sigint_timer):
                    sigint_timer = threading.Timer(0.01, os.kill, args=[pid, signal.SIGINT])
                   ...