Status: Fix output of @cpu if the amount of memory is unknown.

This commit is contained in:
Valentin Lorentz 2015-12-07 16:32:46 +01:00
parent b0ee589702
commit 856d275697

View File

@ -160,7 +160,7 @@ class Status(callbacks.Plugin):
'running.', 'running.',
(world.threadsSpawned, 'thread'), activeThreads) (world.threadsSpawned, 'thread'), activeThreads)
if self.registryValue('cpu.memory', target): if self.registryValue('cpu.memory', target):
mem = 'an unknown amount' mem = None
pid = os.getpid() pid = os.getpid()
plat = sys.platform plat = sys.platform
try: try:
@ -180,8 +180,11 @@ class Status(callbacks.Plugin):
mem = int(out.splitlines()[1]) mem = int(out.splitlines()[1])
elif sys.platform.startswith('netbsd'): elif sys.platform.startswith('netbsd'):
mem = int(os.stat('/proc/%s/mem' % pid)[7]) mem = int(os.stat('/proc/%s/mem' % pid)[7])
response += format(_(' I\'m taking up %S of memory.'), if mem:
mem*1024) response += format(_(' I\'m taking up %S of memory.'),
mem*1024)
else:
response += _(' I\'m taking up an unknown amount of memory.')
except Exception: except Exception:
self.log.exception('Uncaught exception in cpu.memory:') self.log.exception('Uncaught exception in cpu.memory:')
irc.reply(utils.str.normalizeWhitespace(response)) irc.reply(utils.str.normalizeWhitespace(response))