does gunicorn also execute if __name __ == '__main__'

Viewed 609

eg I have a command like this gunicorn --bind 0.0.0.0:8000 --workers = 3 --threads = 3 manage: app then manage: app fetched from manage.py file

app = create_app ()

does the if __name __ == '__ main__' function look like this too

if __name__ == '__main__':
     flask_thread (func = run)
     client.run (os.getenv ('TOKEN'))

executed when running Gunicorn?

1 Answers

Short Answer

No, gunicorn import your app variable and invokes it. The if will not be executed.

Longer Answer

__name__ is a special variable. If we run your module directly using python manage.py then the value is __main__. So, the if is True.

But, if we run your module imported by another (including gunicorn) using something like from manage import app then the value is 'app' or 'manage.app' (you can check it by yourself). Without saying, the if condition will be False.

Related