gunicorn_config.py 709 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. import signal
  3. import sys
  4. import multiprocessing
  5. # 获取环境变量
  6. source_path = os.environ.get('SOURCE_PATH', '/usr/local/WTOAAM')
  7. # Gunicorn configuration settings
  8. bind = f"unix:{source_path}/djangoAPI.sock"
  9. workers = multiprocessing.cpu_count() * 2 + 1
  10. worker_class = "sync"
  11. timeout = 30
  12. loglevel = "info"
  13. def on_starting(server):
  14. print("Starting Gunicorn...")
  15. def when_ready(server):
  16. print("Gunicorn is ready")
  17. def on_exit(server):
  18. print("Stopping Gunicorn...")
  19. def pre_fork(server, worker):
  20. def handle_sigint(signal, frame):
  21. print("Received SIGINT, stopping Gunicorn...")
  22. server.stop()
  23. sys.exit(0)
  24. signal.signal(signal.SIGINT, handle_sigint)