Skip to content

Instantly share code, notes, and snippets.

@MHM5000
Forked from gcavalcante8808/wsgi_bjoern.py
Created October 8, 2021 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MHM5000/922f2af339f7045b7d1b6752fcc7dc8e to your computer and use it in GitHub Desktop.
Save MHM5000/922f2af339f7045b7d1b6752fcc7dc8e to your computer and use it in GitHub Desktop.
Bjoern Django Final
import bjoern
import os, signal
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = get_wsgi_application()
NUM_WORKERS = 8
worker_pids = []
bjoern.listen(app, '0.0.0.0', 8000)
for _ in range(NUM_WORKERS):
pid = os.fork()
if pid > 0:
# in master
worker_pids.append(pid)
elif pid == 0:
# in worker
try:
bjoern.run()
except KeyboardInterrupt:
pass
exit()
try:
# Wait for the first worker to exit. They should never exit!
# Once first is dead, kill the others and exit with error code.
pid, xx = os.wait()
worker_pids.remove(pid)
finally:
for pid in worker_pids:
os.kill(pid, signal.SIGINT)
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment