Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environmental variables not available during '--preload' application start up #735

Closed
tshlabs opened this issue May 6, 2014 · 4 comments · Fixed by #740
Closed

Environmental variables not available during '--preload' application start up #735

tshlabs opened this issue May 6, 2014 · 4 comments · Fixed by #740

Comments

@tshlabs
Copy link
Contributor

tshlabs commented May 6, 2014

Environmental variables set through Gunicorn via the '-e' CLI flag or the 'raw_env' configuration setting are not available during application start up when the application uses the '--preload' flag.

An example program to demonstrate this (using Flask 0.10.1 and Gunicorn 18.0) is here:

https://gist.github.com/tshlabs/eb59186648fd003bf28c

The output from this is the following:

$ gunicorn -b localhost:8000 --preload -e FOO=bar test:application
This is the bootstrap. FOO = None
2014-05-05 20:56:14 [2575] [INFO] Starting gunicorn 18.0
2014-05-05 20:56:14 [2575] [INFO] Listening at: http://127.0.0.1:8000 (2575)
2014-05-05 20:56:14 [2575] [INFO] Using worker: sync
2014-05-05 20:56:14 [2584] [INFO] Booting worker with pid: 2584

However, when the '--preload' flag isn't used the environmental variable is available during application start up.

$ gunicorn -b localhost:8000 -e FOO=bar test:application
2014-05-05 21:06:00 [18244] [INFO] Starting gunicorn 18.0
2014-05-05 21:06:00 [18244] [INFO] Listening at: http://127.0.0.1:8000 (18244)
2014-05-05 21:06:00 [18244] [INFO] Using worker: sync
2014-05-05 21:06:00 [18249] [INFO] Booting worker with pid: 18249
This is the bootstrap. FOO = bar

When visiting 'localhost:8000' in a browser in both cases, the value of the 'FOO' variable is 'bar'.

$ curl http://localhost:8000/
The is the worker. FOO = bar

Is it expected behavior that environmental variables are not available during application start up when using the --preload flag?

@tshlabs tshlabs changed the title Environmental variables not available durring '--preload' application start up Environmental variables not available during '--preload' application start up May 6, 2014
@tilgovi
Copy link
Collaborator

tilgovi commented May 9, 2014

I'm not aware of any good reason why it's this way.
@benoitc could we move the # set environments variables block in Arbiter.start into Arbiter.setup?

@benoitc
Copy link
Owner

benoitc commented May 9, 2014

@tilgovi I don't see any reason coming to my mind actually... It's probably good to set it in the setup function.

@tshlabs
Copy link
Contributor Author

tshlabs commented May 10, 2014

@tilgovi @benoitc Awesome. Thank you. Would you like a pull request?

@tilgovi
Copy link
Collaborator

tilgovi commented May 11, 2014

@tshlabs 👍 ⛵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants