import functools import threading # A decorator that will run its wrapped function in a new thread def run_in_new_thread(function): # functool.wraps will copy over the docstring and some other metadata # from the original function @functools.wraps(function) def fn_(*args, **kwargs): thread = threading.Thread(target=function, args=args, kwargs=kwargs) thread.start() thread.join() return fn_ #usage: import os, webbrowser startfile = run_in_new_thread(os.startfile) openbrowser = run_in_new_thread(webbrowser.open)