Hi Amir,
Richard Lai
11

Hi Richard,

Thanks for reading the post.

Gunicorn workers are not going to have access to the global context (clf) and that’s why you’re seeing the error. Details here:
http://docs.gunicorn.org/en/stable/design.html

If you’re using gunicorn you have to think of each function as a self-contained unit. In this case that means that we have to load the classifier every time the function is called. You can either (1) read from disk using joblib.load or (2) setup a memory store like Redis and load from memory for faster access. If latency is an issue I recommend the second option. I’ve written some code that you might want to reference (apologies for poor documentation in advance):
https://github.com/amirziai/menrva/blob/master/app.py

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.