When you run the server through gunicorn, the __main__ doesn't run, so to fix that I followed the SO recommendation and put the initialisation to the top level (so it happens at import time)
However I am not sure if this is the right way to go. I haven't really verified it running in the gunicorn Docker container, as my computer is terribly slow. I think it may be a problem if/when we start gunicorn with multiple workers.
If we keep gunicorn workers at 1, as we have now, and start multiple processes in our own code, it should be fine? I noticed that when I just run Flask without gunicorn in development mode, it uses two processes, whereas when i run it with FLASK_ENV=production, it uses only 1. When I had two, they both tried to do the garbage collection file deletion. I added some error handling in #72 to solve that problem.
@boonwj Not having this fix could also be related with the errors you mention in #67, as the initialisation from main method is not running when you use gunicorn.
When you run the server through gunicorn, the
__main__
doesn't run, so to fix that I followed the SO recommendation and put the initialisation to the top level (so it happens at import time)However I am not sure if this is the right way to go. I haven't really verified it running in the gunicorn Docker container, as my computer is terribly slow. I think it may be a problem if/when we start gunicorn with multiple workers.
If we keep gunicorn workers at 1, as we have now, and start multiple processes in our own code, it should be fine? I noticed that when I just run Flask without gunicorn in development mode, it uses two processes, whereas when i run it with FLASK_ENV=production, it uses only 1. When I had two, they both tried to do the garbage collection file deletion. I added some error handling in #72 to solve that problem.