Skip to content

Instantly share code, notes, and snippets.

@keyan
Created January 7, 2020 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyan/c00f3e9d7b1026edc5f6cedc8250a388 to your computer and use it in GitHub Desktop.
Save keyan/c00f3e9d7b1026edc5f6cedc8250a388 to your computer and use it in GitHub Desktop.
Background processing in python

For flask servers using gunicorn, which can be configured to use any type of worker. We use gevent workers (flag -k) (which use the libuv event loop under-the-hood, see http://flask.pocoo.org/docs/0.12/deploying/wsgi-standalone/): http://docs.gunicorn.org/en/latest/settings.html#worker-class

This means we can push tasks into the gevent event loop and have them execute outside of a flask request context. As long as all the gunicorn workers aren’t processing these tasks and blocking flask request execution, this should not affect performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment