Skip to content

Instantly share code, notes, and snippets.

@skydark
Created October 24, 2012 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skydark/3945946 to your computer and use it in GitHub Desktop.
Save skydark/3945946 to your computer and use it in GitHub Desktop.
from threading import Thread
import hashlib
def async(gen):
def func(*args, **kwargs):
it = gen(*args, **kwargs)
result = it.next()
Thread(target=lambda: list(it)).start()
return result
return func
@async
def test(text):
# synchronous part (empty in this example)
yield # Use "yield value" if you need to return meaningful value
# asynchronous part[s]
digest = hashlib.md5(text).hexdigest()
print digest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment