Flask render task doesn't works with gevent.
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
import flask | |
import gevent | |
app = flask.Flask(__name__) | |
def task(): | |
print flask.render_template_string('Hello World!') | |
def with_context(): | |
with flask.current_app.test_request_context(): | |
print "with context: ", | |
task() | |
def gevent_task(): | |
result = gevent.spawn(task) | |
result.get() | |
def gevent_with_context(): | |
result = gevent.spawn(with_context) | |
result.get() | |
if __name__ == "__main__": | |
with app.app_context(): | |
# NOT WORKS | |
#task() | |
with_context() | |
# NOT WORKS | |
#gevent_task() | |
gevent_with_context() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment