Created
June 4, 2017 08:21
-
-
Save semyont/cf29f5df06f477f16eee56e7b094036c to your computer and use it in GitHub Desktop.
tornado blocking task gevent workers async example
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
# Do this as early as possible in your application: | |
from gevent import monkey; monkey.patch_all() | |
from tornado.web import RequestHandler, asynchronous | |
import gevent | |
class MyHandler(RequestHandler): | |
@asynchronous | |
def get(self, *args, **kwargs): | |
def async_task(): | |
data = run_blocking_task() | |
self.write(data) | |
self.finish() | |
gevent.spawn(async_task) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment