Skip to content

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

Merged

Conversation

aimestereo
Copy link
Contributor

No description provided.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -395,6 +395,13 @@ def close(self):
def _MultiProcessValue(_pidFunc=os.getpid):
files = {}
values = []

# pid needs to be evaluated here in a master process
Copy link
Contributor

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.

@aimestereo aimestereo force-pushed the fix-multiprocessing-for-celery branch from b3d2f19 to b681e60 Compare September 2, 2017 20:26
@brian-brazil brian-brazil merged commit d858f0d into prometheus:master Sep 3, 2017
@brian-brazil
Copy link
Contributor

Thanks!

@aimestereo aimestereo deleted the fix-multiprocessing-for-celery branch September 5, 2017 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants