mirror of
https://github.com/powerline/powerline.git
synced 2025-07-29 16:55:07 +02:00
Merge branch 'various-improvements' into develop
This commit is contained in:
commit
2685f61e88
@ -412,7 +412,8 @@ class Powerline(object):
|
|||||||
'''
|
'''
|
||||||
self.shutdown_event.set()
|
self.shutdown_event.set()
|
||||||
if self.use_daemon_threads and self.is_alive():
|
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.renderer.shutdown()
|
||||||
self.watcher.unsubscribe()
|
self.watcher.unsubscribe()
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import errno
|
import errno
|
||||||
from powerline.lib.time import monotonic
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
|
from powerline.lib.monotonic import monotonic
|
||||||
|
|
||||||
class INotifyError(Exception):
|
class INotifyError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from powerline.lib.time import monotonic
|
from powerline.lib.monotonic import monotonic
|
||||||
|
|
||||||
|
|
||||||
def default_cache_key(**kwargs):
|
def default_cache_key(**kwargs):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from powerline.lib.time import monotonic
|
from powerline.lib.monotonic import monotonic
|
||||||
|
|
||||||
from threading import Thread, Lock, Event
|
from threading import Thread, Lock, Event
|
||||||
|
|
||||||
@ -77,7 +77,8 @@ class ThreadedSegment(object):
|
|||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.shutdown_event.set()
|
self.shutdown_event.set()
|
||||||
if self.daemon and self.is_alive():
|
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):
|
def set_interval(self, interval=None):
|
||||||
# Allowing “interval” keyword in configuration.
|
# Allowing “interval” keyword in configuration.
|
||||||
|
@ -7,17 +7,18 @@ import sys
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import socket
|
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 import add_divider_highlight_group
|
||||||
from powerline.lib.url import urllib_read, urllib_urlencode
|
from powerline.lib.url import urllib_read, urllib_urlencode
|
||||||
from powerline.lib.vcs import guess
|
from powerline.lib.vcs import guess
|
||||||
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment, with_docstring
|
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.lib.humanize_bytes import humanize_bytes
|
||||||
from powerline.theme import requires_segment_info
|
from powerline.theme import requires_segment_info
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
cpu_count = None
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def hostname(pl, segment_info, only_if_ssh=False, exclude_domain=False):
|
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):
|
class ExternalIpSegment(ThreadedSegment):
|
||||||
interval = 10
|
interval = 300
|
||||||
|
|
||||||
def set_state(self, query_url='http://ipv4.icanhazip.com/', **kwargs):
|
def set_state(self, query_url='http://ipv4.icanhazip.com/', **kwargs):
|
||||||
self.query_url = query_url
|
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.
|
'''Return system load average.
|
||||||
|
|
||||||
Highlights using ``system_load_good``, ``system_load_bad`` and
|
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:
|
indicates relative position in this interval:
|
||||||
(``100 * (cur-good) / (bad-good)``).
|
(``100 * (cur-good) / (bad-good)``).
|
||||||
Note: both parameters are checked against normalized load averages.
|
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``.
|
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
|
global cpu_count
|
||||||
try:
|
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:
|
except NotImplementedError:
|
||||||
pl.warn('Unable to get CPU count: method is not implemented')
|
pl.warn('Unable to get CPU count: method is not implemented')
|
||||||
return None
|
return None
|
||||||
|
@ -231,7 +231,7 @@ class TestCommon(TestCase):
|
|||||||
def test_system_load(self):
|
def test_system_load(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
with replace_module_module(common, 'os', getloadavg=lambda: (7.5, 3.5, 1.5)):
|
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),
|
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': '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},
|
{'contents': '3.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user