Created
May 26, 2016 01:26
-
-
Save comfuture/932df8148b7e14e145fa4172132604f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
try: | |
import gevent | |
except ImportError: | |
pass | |
def async(fn): | |
def decorator(*args, **kwargs): | |
# if use_greenlet: | |
gevent.spawn(fn, *args, **kwargs) | |
# else: | |
# Thread(target=fn, args=tuple(args), kwargs=kwargs) | |
return decorator | |
class Foo(object): | |
def __init__(self, use_greenlet=False): | |
self.use_greenlet = use_greenlet | |
@async | |
def do_job(self, param1): | |
print("done", param1) | |
if __name__ == '__main__': | |
foo = Foo(use_greenlet=True) | |
foo.do_job("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment