8000 values: add a docstring to MultiProcessValue (#514) · dedic247/client_python@ce7063f · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce7063f

Browse files
authored
values: add a docstring to MultiProcessValue (prometheus#514)
To document the method as semi-supported. Signed-off-by: Xavier Fernandez <xavier.fernandez@polyconseil.fr>
1 parent 484ed71 commit ce7063f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

prometheus_client/values.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ def get(self):
2828
return self._value
2929

3030

31-
def MultiProcessValue(_pidFunc=os.getpid):
31+
def MultiProcessValue(process_identifier=os.getpid):
32+
"""Returns a MmapedValue class based on a process_identifier function.
33+
34+
The 'process_identifier' function MUST comply with this simple rule:
35+
when called in simultaneously running processes it MUST return distinct values.
36+
37+
Using a different function than the default 'os.getpid' is at your own risk.
38+
"""
3239
files = {}
3340
values = []
34-
pid = {'value': _pidFunc()}
41+
pid = {'value': process_identifier()}
3542
# Use a single global lock when in multi-processing mode
3643
# as we presume this means there is no threading going on.
3744
# This avoids the need to also have mutexes in __MmapDict.
@@ -66,7 +73,7 @@ def __reset(self):
6673
self._value = self._file.read_value(self._key)
6774

6875
def __check_for_pid_change(self):
69-
actual_pid = _pidFunc()
76+
actual_pid = process_identifier()
7077
if pid['value'] != actual_pid:
7178
pid['value'] = actual_pid
7279
# There has been a fork(), reset all the values.

0 commit comments

Comments
 (0)
0