Flask throwing 'working outside of request context' when starting sub thread

后端 未结 5 1766
遇见更好的自我
遇见更好的自我 2020-11-30 21:23

I am trying to start a new thread in Python inside of a Flask application. I am doing background work that gets triggered by the request, but I don\'t need to wait for the

5条回答
  •  执念已碎
    2020-11-30 21:43

    Since version 0.10 there is a supported way of doing this: http://flask.pocoo.org/docs/api/#flask.copy_current_request_context

    If you want the before_request hooks to run you must call current_app.preprocess_request() inside of the decorated function.

提交回复
热议问题