Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ paver==1.2.2
wheel==0.24.0
pip==1.5.6
sh==1.09
python-prctl==1.6.1
23 changes: 23 additions & 0 deletions sideboard/lib/_threads.py
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
Copy link
Copy Markdown
Member

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:

Traceback (most recent call last):
  File "/home/vagrant/uber/sideboard/env/lib/python3.4/site-packages/_pytest/config.py", line 513, in getconftestmodules
    return self._path2confmods[path]
KeyError: local('/home/vagrant/uber/sideboard/plugins/uber/uber/tests')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/vagrant/uber/sideboard/env/lib/python3.4/site-packages/_pytest/config.py", line 537, in importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('/home/vagrant/uber/sideboard/plugins/uber/conftest.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/vagrant/uber/sideboard/sideboard/__init__.py", line 9, in <module>
    import sideboard.server
  File "/home/vagrant/uber/sideboard/sideboard/server.py", line 10, in <module>
    from sideboard.internal import connection_checker
  File "/home/vagrant/uber/sideboard/sideboard/internal/connection_checker.py", line 7, in <module>
    from sideboard.lib import services, entry_point
  File "/home/vagrant/uber/sideboard/sideboard/lib/__init__.py", line 13, in <module>
    from sideboard.lib._threads import DaemonTask, Caller, GenericCaller, TimeDelayQueue
  File "/home/vagrant/uber/sideboard/sideboard/lib/_threads.py", line 4, in <module>
    import prctl
ImportError: No module named 'prctl'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/vagrant/uber/sideboard/env/lib/python3.4/site-packages/_pytest/config.py", line 543, in importconftest
    mod = conftestpath.pyimport()
  File "/home/vagrant/uber/sideboard/env/lib/python3.4/site-packages/py/_path/local.py", line 650, in pyimport
    __import__(modname)
  File "/home/vagrant/uber/sideboard/plugins/uber/conftest.py", line 1, in <module>
    import sideboard
  File "/home/vagrant/uber/sideboard/sideboard/__init__.py", line 11, in <module>
    from sideboard.lib import log
  File "/home/vagrant/uber/sideboard/sideboard/lib/__init__.py", line 13, in <module>
    from sideboard.lib._threads import DaemonTask, Caller, GenericCaller, TimeDelayQueue
  File "/home/vagrant/uber/sideboard/sideboard/lib/_threads.py", line 4, in <module>
    import prctl
ImportError: No module named 'prctl'
ERROR: could not load /home/vagrant/uber/sideboard/plugins/uber/conftest.py

Copy link
Copy Markdown
Member

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.

import threading
import sys
from warnings import warn
from threading import Thread, Timer, Event, Lock

Expand All @@ -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')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

notes:
in python3, the inner function is named threading.Thread._bootstrap_inner
in python2, the inner function is named threading.Thread._Thread__bootstrap


class DaemonTask(object):
def __init__(self, func, interval=0.1, threads=1):
self.lock = Lock()
Expand Down