Last active
April 27, 2017 16:20
-
-
Save zhouqiang-cl/9345774cd0f9fdea92d10bceb6246a21 to your computer and use it in GitHub Desktop.
run_in_thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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