Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions prometheus_client/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ def get(self):
return self._value


def MultiProcessValue(_pidFunc=os.getpid):
def MultiProcessValue(process_identifier=os.getpid):
"""Returns a MmapedValue class based on a process_identifier function.
The 'process_identifier' function MUST comply with this simple rule:
Comment thread
xavfernandez marked this conversation as resolved.
Resolved
when called in simultaneously running processes it MUST return distinct values.
Using a different function than the default 'os.getpid' is at your own risk.
"""
files = {}
values = []
pid = {'value': _pidFunc()}
pid = {'value': process_identifier()}
# Use a single global lock when in multi-processing mode
# as we presume this means there is no threading going on.
# This avoids the need to also have mutexes in __MmapDict.
Expand Down Expand Up @@ -66,7 +73,7 @@ def __reset(self):
self._value = self._file.read_value(self._key)

def __check_for_pid_change(self):
actual_pid = _pidFunc()
actual_pid = process_identifier()
if pid['value'] != actual_pid:
pid['value'] = actual_pid
# There has been a fork(), reset all the values.
Expand Down