Merge branch 'various-improvements' into develop

This commit is contained in:
Kim Silkebækken 2013-04-05 16:22:46 +02:00
commit 2685f61e88
7 changed files with 17 additions and 11 deletions

View File

@ -412,7 +412,8 @@ class Powerline(object):
'''
self.shutdown_event.set()
if self.use_daemon_threads and self.is_alive():
self.thread.join()
# Give the worker thread a chance to shutdown, but don't block for too long
self.thread.join(.01)
self.renderer.shutdown()
self.watcher.unsubscribe()

View File

@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
import os
import sys
import errno
from powerline.lib.time import monotonic
from time import sleep
from threading import RLock
from powerline.lib.monotonic import monotonic
class INotifyError(Exception):
pass

View File

@ -1,7 +1,7 @@
# vim:fileencoding=utf-8:noet
from functools import wraps
from powerline.lib.time import monotonic
from powerline.lib.monotonic import monotonic
def default_cache_key(**kwargs):

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import
from powerline.lib.time import monotonic
from powerline.lib.monotonic import monotonic
from threading import Thread, Lock, Event
@ -77,7 +77,8 @@ class ThreadedSegment(object):
def shutdown(self):
self.shutdown_event.set()
if self.daemon and self.is_alive():
self.thread.join()
# Give the worker thread a chance to shutdown, but don't block for too long
self.thread.join(.01)
def set_interval(self, interval=None):
# Allowing “interval” keyword in configuration.

View File

@ -7,17 +7,18 @@ import sys
from datetime import datetime
import socket
from multiprocessing import cpu_count
from multiprocessing import cpu_count as _cpu_count
from powerline.lib import add_divider_highlight_group
from powerline.lib.url import urllib_read, urllib_urlencode
from powerline.lib.vcs import guess
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment, with_docstring
from powerline.lib.time import monotonic
from powerline.lib.monotonic import monotonic
from powerline.lib.humanize_bytes import humanize_bytes
from powerline.theme import requires_segment_info
from collections import namedtuple
cpu_count = None
@requires_segment_info
def hostname(pl, segment_info, only_if_ssh=False, exclude_domain=False):
@ -245,7 +246,7 @@ def _external_ip(query_url='http://ipv4.icanhazip.com/'):
class ExternalIpSegment(ThreadedSegment):
interval = 10
interval = 300
def set_state(self, query_url='http://ipv4.icanhazip.com/', **kwargs):
self.query_url = query_url
@ -485,7 +486,7 @@ Also uses ``weather_conditions_{condition}`` for all weather conditions supporte
''')
def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2):
def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, track_cpu_count=False):
'''Return system load average.
Highlights using ``system_load_good``, ``system_load_bad`` and
@ -504,6 +505,9 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2):
indicates relative position in this interval:
(``100 * (cur-good) / (bad-good)``).
Note: both parameters are checked against normalized load averages.
:param bool track_cpu_count:
if True powerline will continuously poll the system to detect changes
in the number of CPUs.
Divider highlight group used: ``background:divider``.
@ -511,7 +515,7 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2):
'''
global cpu_count
try:
cpu_num = cpu_count()
cpu_num = cpu_count = _cpu_count() if cpu_count is None or track_cpu_count else cpu_count
except NotImplementedError:
pl.warn('Unable to get CPU count: method is not implemented')
return None

View File

@ -231,7 +231,7 @@ class TestCommon(TestCase):
def test_system_load(self):
pl = Pl()
with replace_module_module(common, 'os', getloadavg=lambda: (7.5, 3.5, 1.5)):
with replace_attr(common, 'cpu_count', lambda: 2):
with replace_attr(common, '_cpu_count', lambda: 2):
self.assertEqual(common.system_load(pl=pl),
[{'contents': '7.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 100},
{'contents': '3.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0},