From 8b06ab32a9cebec7f53069676972da3a534f3c20 Mon Sep 17 00:00:00 2001 From: Hashim1999164 <64767361+Hashim1999164@users.noreply.github.com> Date: Wed, 26 Aug 2026 18:13:39 +0500 Subject: [PATCH] Skip mark_process_dead when the multiprocess path is unset django_q and similar callers invoke this even when PROMETHEUS_MULTIPROC_DIR is missing. Return instead of passing None into os.path.join. Signed-off-by: Hashim1999164 <64767361+Hashim1999164@users.noreply.github.com> --- prometheus_client/multiprocess.py | 2 ++ tests/test_multiprocess.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/prometheus_client/multiprocess.py b/prometheus_client/multiprocess.py index db55874e..046bb2c2 100644 --- a/prometheus_client/multiprocess.py +++ b/prometheus_client/multiprocess.py @@ -178,6 +178,8 @@ def mark_process_dead(pid, path=None): """Do bookkeeping for when one process dies in a multi-process setup.""" if path is None: path = os.environ.get('PROMETHEUS_MULTIPROC_DIR', os.environ.get('prometheus_multiproc_dir')) + if not path: + return for mode in _LIVE_GAUGE_MULTIPROCESS_MODES: for f in glob.glob(os.path.join(path, f'gauge_{mode}_{pid}.db')): os.remove(f) diff --git a/tests/test_multiprocess.py b/tests/test_multiprocess.py index eab93f50..2b68e67b 100644 --- a/tests/test_multiprocess.py +++ b/tests/test_multiprocess.py @@ -51,6 +51,11 @@ def test_mark_process_dead_respects_lowercase(self): # logic is tested elsewhere. mark_process_dead(123) + def test_mark_process_dead_noop_when_path_unset(self): + os.environ.pop('prometheus_multiproc_dir', None) + os.environ.pop('PROMETHEUS_MULTIPROC_DIR', None) + mark_process_dead(123) + class TestMultiProcess(unittest.TestCase): def setUp(self):