Created
October 24, 2012 13:03
-
-
Save skydark/3945946 to your computer and use it in GitHub Desktop.
async using generator http://stackoverflow.com/questions/1696152/easy-python-async-precompiler #python
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 | |
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