Skip to content

Instantly share code, notes, and snippets.

@m4scosta
Created January 5, 2017 02:06
Show Gist options
  • Save m4scosta/d2f75051a8bcac19160a5da7e3c11a47 to your computer and use it in GitHub Desktop.
Save m4scosta/d2f75051a8bcac19160a5da7e3c11a47 to your computer and use it in GitHub Desktop.
Async annotation
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