Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2012 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4299652 to your computer and use it in GitHub Desktop.
Save anonymous/4299652 to your computer and use it in GitHub Desktop.
Flask render task doesn't works with gevent.
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