Merge pull request #838 from ZyX-I/new-psutil-fixes

New psutil fixes
This commit is contained in:
ZyX-I 2014-03-13 19:32:39 +03:00
commit 534b0434f3
2 changed files with 20 additions and 3 deletions

View File

@ -517,8 +517,14 @@ try:
if data:
yield interface, data.bytes_recv, data.bytes_sent
def _get_user(segment_info):
return psutil.Process(os.getpid()).username
# psutil-2.0.0: psutil.Process.username is unbound method
if callable(psutil.Process.username):
def _get_user(segment_info):
return psutil.Process(os.getpid()).username()
# pre psutil-2.0.0: psutil.Process.username has type property
else:
def _get_user(segment_info):
return psutil.Process(os.getpid()).username
class CPULoadPercentSegment(ThreadedSegment):
interval = 1

View File

@ -169,7 +169,18 @@ class TestCommon(TestCase):
def test_user(self):
new_os = new_module('os', getpid=lambda: 1)
new_psutil = new_module('psutil', Process=lambda pid: Args(username='def'))
class Process(object):
def __init__(self, pid):
pass
def username(self):
return 'def'
if hasattr(common, 'psutil') and not callable(common.psutil.Process.username):
username = property(username)
new_psutil = new_module('psutil', Process=Process)
pl = Pl()
with replace_env('USER', 'def') as segment_info:
common.username = False