Last active
December 31, 2015 01:58
-
-
Save amitm/7917259 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
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