Skip to content

Instantly share code, notes, and snippets.

@zhouqiang-cl
Last active April 27, 2017 16:20
Show Gist options
  • Save zhouqiang-cl/9345774cd0f9fdea92d10bceb6246a21 to your computer and use it in GitHub Desktop.
Save zhouqiang-cl/9345774cd0f9fdea92d10bceb6246a21 to your computer and use it in GitHub Desktop.
run_in_thread
import threading
from functools import wraps
threads = []
def run_in_thread(join=False):
def decorator(f):
@wraps(f)
def wrapper(*args, **kwds):
t = threading.Thread(target=f,args=args,kwargs=kwds)
threads.append(t)
t.start()
if join:
for t in threads:
try:
t.join()
except:
pass
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment