-2

I would like to be able to distinguish between development and production environment.

Use Case

I have a huge legacy code base (python) before me.

I am unsure whether some methods are still used in production or not.

My current strategy

I want to raise an exception if the code gets used in a development environment. But on production the exception should not get raised, but a warning should get emitted. If there is no warning in about 3 months, then I know with probability bordering on certainty that this code can be removed.

Question

How to Dinstinguish between Development and Production Environment

guettli
  • 25,042
  • 81
  • 346
  • 663
  • 3
    This really isn't a Python problem, it's a 'how are my deployment environments differently defined and configured' problem. Unless you can tell us that, we can't help. If you can tell us that, you probably don't need our help. – Simon Hibbs Apr 05 '17 at 11:46
  • @SimonHibbs yes, you are right. This issue needs to solved at a higher level, not python. Where can I ask this question, if not here? – guettli Apr 05 '17 at 13:15
  • I think it's really a sysadmin, operational or even architectural issue. For example in one shop I worked at each database stored a parameter that indicated whether it was prod, dev, etc and our code queried that to tell what env it was in. Setting this at the infrastructure level is probably the right way to go. – Simon Hibbs Apr 05 '17 at 14:58
  • @SimonHibbs yes a parameter in the database could help. Is there no "best practice" yet? – guettli Apr 06 '17 at 09:21

1 Answers1

1

I have 2 ways:

  1. Use a global variable to detect current environment. You can define this variable in a file config.py or pass as a ENVIRONMENT VARIABLE in session when run code: $DEV_ENV=1 python run.py

  2. Deploy 2 instance in docker, it like as 2 application run in 2 distinguish systems, best for distinguish environments

loc.truong
  • 11
  • 2