Question

We need to load different configuration options in our Python WSGI application, according to production or debugging environments (particularly, some server configuration information relating to the task server to which the application needs to post jobs). The way we have implemented it so far is to have a global debug variable that gets set in our deployment script - which does modify the deployment setup correctly. However, when we execute the application, we need to set the debug variable to True - since its default value is False.

So far, it is hard to correctly determine the way the debug variable works, because it is set at deploy time, not execute time. We can set it before calling the serve_forever method of our debug WSGI server, but I am not aware of the implications of this and how good that solution is.

What is the usual pattern for differentiating between debug and production environments in WSGI applications? If I need to pass it in system arguments, or if there is any other, different way, please let me know. Thanks very much!

Was it helpful?

Solution

If your setup allows it, consider using environment variables. Your production servers could have one value for an environment variable while dev servers have another. Then on execution of your application you can detect the value of the environment variable and set "debug" accordingly.

OTHER TIPS

I don't like using environment variables. Try to make it working with your application configuration, which can be overwrite by:

  • importing non versioned files (in dev environment), wrapped by try-except with proper log notification.
  • command line arguments (argparse from standard library)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top