_context.py 759 B

1234567891011121314151617181920212223242526272829303132
  1. # @description:
  2. # @author: licanglong
  3. # @date: 2025/12/23 13:49
  4. import threading
  5. from typing import Optional
  6. from app.core._configs import ConfigEnvironmentInstance
  7. class AppContext:
  8. _instance_lock = threading.Lock()
  9. _instance: Optional["AppContext"] = None
  10. DEFAULT_CONFIG_FILE = "env/env.yml"
  11. DEFAULT_LOG_FILE = "logs/app.log"
  12. def __new__(cls):
  13. if cls._instance is None:
  14. with cls._instance_lock:
  15. if cls._instance is None:
  16. cls._instance = super().__new__(cls)
  17. return cls._instance
  18. def __init__(self):
  19. if hasattr(self, "_initialized"):
  20. return
  21. self.ENV = ConfigEnvironmentInstance()
  22. self._initialized = True
  23. CTX = AppContext()