diff --git a/.travis.yml b/.travis.yml index 9b35c7d..59d3f0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ env: - TOX_ENV=py27 - TOX_ENV=py33 - TOX_ENV=py34 +before_install: + - sudo apt-get -qq update + - sudo apt-get install -y build-essential libcap-dev install: - pip install tox - pip install python-coveralls diff --git a/requirements.txt b/requirements.txt index ae3f855..d3df306 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ paver==1.2.2 wheel==0.24.0 pip==1.5.6 sh==1.09 +python-prctl==1.6.1 \ No newline at end of file diff --git a/sideboard/lib/_threads.py b/sideboard/lib/_threads.py index c8b8d37..d493821 100644 --- a/sideboard/lib/_threads.py +++ b/sideboard/lib/_threads.py @@ -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') + + class DaemonTask(object): def __init__(self, func, interval=0.1, threads=1): self.lock = Lock()