Skip to content

Instantly share code, notes, and snippets.

@amitm
Last active December 31, 2015 01:58
Show Gist options
  • Save amitm/7917259 to your computer and use it in GitHub Desktop.
Save amitm/7917259 to your computer and use it in GitHub Desktop.
import tornado.gen
import database
original_runner_init = tornado.gen.Runner.__init__
original_runner_run = tornado.gen.Runner.run
original_runner_handle_exception = tornado.gen.Runner.handle_exception
def new_runner_init(self, *args, **kwargs):
original_runner_init(self, *args, **kwargs)
self.scope = database.scope.get()
def new_runner_run(self, *args, **kwargs):
database.scope.restore(self.scope)
return original_runner_run(self, *args, **kwargs)
tornado.gen.Runner.__init__ = new_runner_init
tornado.gen.Runner.run = new_runner_run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment