From f8c58408fec0d2a08d691e42b023bd28d2c177ee Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Thu, 20 Nov 2025 11:07:04 +0530 Subject: [PATCH] `uwsgi`: Remove postfork hooks Signed-off-by: Varsha GS --- src/instana/__init__.py | 1 - src/instana/hooks/hook_uwsgi.py | 54 --------------------------------- 2 files changed, 55 deletions(-) delete mode 100644 src/instana/hooks/hook_uwsgi.py diff --git a/src/instana/__init__.py b/src/instana/__init__.py index f9511537..5d66246e 100644 --- a/src/instana/__init__.py +++ b/src/instana/__init__.py @@ -213,7 +213,6 @@ def boot_agent() -> None: # Hooks from instana.hooks import ( hook_gunicorn, # noqa: F401 - hook_uwsgi, # noqa: F401 ) diff --git a/src/instana/hooks/hook_uwsgi.py b/src/instana/hooks/hook_uwsgi.py deleted file mode 100644 index 1995ffeb..00000000 --- a/src/instana/hooks/hook_uwsgi.py +++ /dev/null @@ -1,54 +0,0 @@ -# (c) Copyright IBM Corp. 2021 -# (c) Copyright Instana Inc. 2019 - -""" -The uwsgi and uwsgidecorators packages are added automatically to the Python environment -when running under uWSGI. Here we attempt to detect the presence of these packages and -then use the appropriate hooks. -""" - -try: - from instana.log import logger - from instana.singletons import agent - - import uwsgi - - logger.debug( - f"uWSGI options: {uwsgi.opt}", - ) - - opt_master = uwsgi.opt.get("master", False) - opt_lazy_apps = uwsgi.opt.get("lazy-apps", False) - - if not uwsgi.opt.get("enable-threads", False) and not uwsgi.opt.get( - "gevent", False - ): - logger.warning( - "Required: Neither uWSGI threads or gevent is enabled. " - + "Please enable by using the uWSGI --enable-threads or --gevent option." - ) - - if opt_master and not opt_lazy_apps: - # --master is supplied in uWSGI options (otherwise uwsgidecorators package won't be available) - # When --lazy-apps is True, this postfork hook isn't needed - import uwsgidecorators - - @uwsgidecorators.postfork - def uwsgi_handle_fork() -> None: - """This is our uWSGI hook to detect and act when worker processes are forked off.""" - logger.debug("Handling uWSGI fork...") - agent.handle_fork() - - logger.debug("Applied uWSGI hooks") - else: - logger.debug( - f"uWSGI --master={opt_master} --lazy-apps={opt_lazy_apps}: postfork hooks not applied" - ) - -except ImportError: - logger.debug( - "uwsgi hooks: decorators not available: likely not running under uWSGI" - ) - -except AttributeError: - logger.debug("uwsgi hooks: Running under uWSGI but decorators not available")