-
Notifications
You must be signed in to change notification settings - Fork 823
Fix multi process collision by initializing pid variable in master process #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multi process collision by initializing pid variable in master process #192
Conversation
prometheus_client/core.py
Outdated
@@ -395,6 +395,14 @@ def close(self): | |||
def _MultiProcessValue(_pidFunc=os.getpid): | |||
files = {} | |||
values = [] | |||
|
|||
# 1. use dict instead of nonlocal keyword to support python 2.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't adding much to someone familiar with Python, I'd remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
prometheus_client/core.py
Outdated
files[file_prefix] = _MmapedDict(filename) | ||
self._file = files[file_prefix] | ||
self._key = json.dumps((metric_name, name, labelnames, labelvalues)) | ||
self._value = self._file.read_value(self._key) | ||
|
||
def __check_for_pid_change(self): | ||
if self._pid != _pidFunc(): | ||
actual_pid = _pidFunc() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove this blank line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
prometheus_client/core.py
Outdated
@@ -395,6 +395,13 @@ def close(self): | |||
def _MultiProcessValue(_pidFunc=os.getpid): | |||
files = {} | |||
values = [] | |||
|
|||
# pid needs to be evaluated here in a master process |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's usage dependant, not all relevant systems have masters. I think it'll be fine not to have this comment at all.
b3d2f19
to
b681e60
Compare
Thanks! |
No description provided.