import traceback
import time


def wrapLoop(loopfunc):
    """Wraps a thread in a wrapper function to restart it if it exits."""
    def wrapped():
        while True:
            try:
                loopfunc()
            except BaseException:
                print(f"Exception in thread {loopfunc},"
                      " restarting in 10s...")
                traceback.print_exc()
            else:
                print(f"Thread {loopfunc} exited, restarting in 10s...")
            time.sleep(10)
    return wrapped