-
Notifications
You must be signed in to change notification settings - Fork 13
set thread names on startup #21
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ecc4a47
set thread names on startup
binary1230 6b51bca
made use of prctl switch on Python version
EliAndrewC 51a6473
install libcap for travis builds
binary1230 da18ab6
install libcap-dev for travis builds instead of just libcap
binary1230 27c52f4
Merge remote-tracking branch 'origin/name_threads' into name_threads
binary1230 0c3b3d0
fix python2 prctl dependencies / install / thread bootstrap function
binary1230 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,4 @@ paver==1.2.2 | |
| wheel==0.24.0 | ||
| pip==1.5.6 | ||
| sh==1.09 | ||
| python-prctl==1.6.1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| from __future__ import unicode_literals | ||
| import time | ||
| import heapq | ||
| import prctl | ||
| import threading | ||
| import sys | ||
| from warnings import warn | ||
| from threading import Thread, Timer, Event, Lock | ||
|
|
||
|
|
@@ -9,6 +12,26 @@ | |
| from sideboard.lib import log, on_startup, on_shutdown | ||
|
|
||
|
|
||
| # inject our own code at the start of every thread's start() method which sets the thread name via prctl(). | ||
| # Python thread names will now be shown in external system tools like 'top', '/proc', etc. | ||
| def _thread_name_insert(self): | ||
| if self.name: | ||
| # linux doesn't allow thread names > 15 chars, and we ideally want to see the end of the name. | ||
| # attempt to shorten the name if we need to. | ||
| shorter_name = self.name if len(self.name) < 15 else self.name.replace('CP Server Thread', 'CPServ') | ||
| prctl.set_name(shorter_name) | ||
| threading.Thread._bootstrap_inner_original(self) | ||
| if sys.version_info[0] == 3: | ||
| threading.Thread._bootstrap_inner_original = threading.Thread._bootstrap_inner | ||
| threading.Thread._bootstrap_inner = _thread_name_insert | ||
| else: | ||
| threading.Thread._bootstrap_inner_original = threading.Thread._Thread__bootstrap | ||
| threading.Thread._Thread__bootstrap = _thread_name_insert | ||
|
|
||
| # set the name of the main thread | ||
| prctl.set_name('sideboard_main') | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notes: |
||
|
|
||
| class DaemonTask(object): | ||
| def __init__(self, func, interval=0.1, threads=1): | ||
| self.lock = Lock() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Yo, this has broken my ability to run unit tests:
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.
From Dom in Slack, this is because the module isn't installed and re-running puppet (
cd ~/uber/puppet && ./apply_node.sh localhost) will make it work.