Created
January 5, 2017 02:06
-
-
Save m4scosta/d2f75051a8bcac19160a5da7e3c11a47 to your computer and use it in GitHub Desktop.
Async annotation
This file contains 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
from threading import Thread | |
from functools import wraps | |
def async(func): | |
""" | |
Wraps the func execution with a thread. | |
Usage: | |
@async | |
def my_task(): | |
time.sleep(1) | |
print('my_task done') | |
th1 = my_task() | |
print('main') | |
th1.join() | |
""" | |
@wraps(func) | |
def async_func(*args, **kwargs): | |
func_hl = Thread(target = func, args = args, kwargs = kwargs) | |
func_hl.start() | |
return func_hl | |
return async_func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment