Created
June 14, 2022 20:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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