django-socketify-wsgi.py 668 B

12345678910111213141516171819202122232425262728293031
  1. from socketify import WSGI
  2. import os
  3. import multiprocessing
  4. import logging
  5. from hello_socketify.hello.wsgi import application
  6. _is_travis = os.environ.get('TRAVIS') == 'true'
  7. workers = int(multiprocessing.cpu_count())
  8. if _is_travis:
  9. workers = 2
  10. def run_app():
  11. WSGI(application).listen(8080, lambda config: logging.info(f"Listening on port http://localhost:{config.port} now\n")).run()
  12. def create_fork():
  13. n = os.fork()
  14. # n greater than 0 means parent process
  15. if not n > 0:
  16. run_app()
  17. # fork limiting the cpu count - 1
  18. for i in range(1, multiprocessing.cpu_count()):
  19. create_fork()
  20. run_app() # run app on the main process too :)