If ``check_in_thread`` is False, ``main_func`` will be run in a separate
    thread, and the code checker in the main thread. This was the original
    behavior of this module: I (Michael Elsdoerfer) changed the default
    to be the reverse: Code checker in thread, main func in main thread.
    This was necessary to make the thing work with Twisted
    (http://twistedmatrix.com/trac/ticket/4072).

def python_reloader(main_func, args, kwargs, check_in_thread=True):
    """
    If ``check_in_thread`` is False, ``main_func`` will be run in a separate
    thread, and the code checker in the main thread. This was the original
    behavior of this module: I (Michael Elsdoerfer) changed the default
    to be the reverse: Code checker in thread, main func in main thread.
    This was necessary to make the thing work with Twisted
    (http://twistedmatrix.com/trac/ticket/4072).
    """
    if os.environ.get("RUN_MAIN") == "true":
        if check_in_thread:
            thread.start_new_thread(reloader_thread, (), {'softexit': False})
        else:
            thread.start_new_thread(main_func, args, kwargs)

        try:
            if not check_in_thread:
                reloader_thread(softexit=True)
            else:
                main_func(*args, **kwargs)
        except KeyboardInterrupt:
            pass
    else:
        try:
            sys.exit(restart_with_reloader())
        except KeyboardInterrupt:
            pass