Skip to content

Instantly share code, notes, and snippets.

@semyont
Created June 4, 2017 08:21
Show Gist options
  • Save semyont/cf29f5df06f477f16eee56e7b094036c to your computer and use it in GitHub Desktop.
Save semyont/cf29f5df06f477f16eee56e7b094036c to your computer and use it in GitHub Desktop.
tornado blocking task gevent workers async example
# 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