Skip to content

Instantly share code, notes, and snippets.

@pcperini
Created June 13, 2012 20:38
Show Gist options
  • Save pcperini/2926385 to your computer and use it in GitHub Desktop.
Save pcperini/2926385 to your computer and use it in GitHub Desktop.
Run Methods Asynchronously with a Simple Decorator
import threading
def _async(func, *a, **kw):
thread = threading.Thread(target = func, args = a, kwargs = kw)
thread.start()
return thread
def async(func):
return lambda *a, **kw: _async(func, *a, **kw)
import time
from async import async
@async
def async_example(arg):
time.sleep(5)
print arg
def example():
async_example("world")
print "hello"
# >>> hello
# >>> world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment