flask application with background threads

前端 未结 4 993
北恋
北恋 2020-12-13 01:07

I am creating a flask application, for one request I need to run some long running job which is not required to wait on the UI. I will create a thread and send a message to

4条回答
  •  無奈伤痛
    2020-12-13 01:27

    The best thing to do for stuff like this is use a message broker. There is some excellent software in the python world meant for doing just this:

    • Celery (http://www.celeryproject.org/), and
    • RQ (http://python-rq.org/).

    Both are excellent choices.

    It's almost never a good idea to spawn a thread the way you're doing it, as this can cause issues processing incoming requests, among other things.

    If you take a look at the celery or RQ getting started guides, they'll walk you through doing this the proper way!

提交回复
热议问题