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):