Skip to content

Instantly share code, notes, and snippets.

@pb-dod
Created June 14, 2022 20:41
Show Gist options
  • Save pb-dod/231b1b5dac9ea296918346a9288a598a to your computer and use it in GitHub Desktop.
Save pb-dod/231b1b5dac9ea296918346a9288a598a to your computer and use it in GitHub Desktop.
example of checking whether you're inside of a uWSGI pre-fork worker
try:
import uwsgi
is_using_uwsgi = True
except ImportError:
is_using_uwsgi = False
def is_uwsgi_prefork():
"""Checks if code is currently being executed within a uWSGI pre-fork worker."""
if is_using_uwsgi:
if uwsgi.numproc > 1 and uwsgi.worker_id() == 0:
return True
return False
if is_uwsgi_prefork():
raise RuntimeError(
'Unable to initalize Launch Darkly client in a uWSGI pre-fork worker.'
' This causes issues with the threads used to check for flag updates.'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment