Differentiating a debugging and production environment in a WSGI application

We need to load various configuration parameters in our Python WSGI application according to production or debugging environments (in particular, server configuration information related to the task server to which the application should send tasks). So far, we have implemented the global debug variable, which is set in our deployment script - this correctly changes the deployment setting. However, when running the application, we need to set the debugging variable True - since its default value is False .

It is still difficult to correctly determine how the debugging variable works, since it is set during deployment, and not for execution time. We can set it before calling the serve_forever method of our debug WSGI server, but I don’t know about the consequences of this and how good this solution is.

What is the usual pattern for separating debugging and production environments in WSGI applications? If I need to pass it in system arguments, or if there is another, different way, please let me know. Thank you very much!

+4
source share
2 answers

If your setup allows this, consider using environment variables. Your production servers may have one value for the environment variable, and development servers may have another. Then, when you run your application, you can determine the value of the environment variable and set "debug" accordingly.

+2
source

I don't like environment variables. Try making it work with your application configuration, which can be overwritten:

  • import non-versioned files (in the dev environment) wrapped by try-except with proper log notification.
  • command line arguments ( argparse from the standard library)
+1
source

All Articles