From fca72de090ea6bd1d57bf89994724b59e106efa1 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Thu, 5 Oct 2006 11:25:05 +0000 Subject: [PATCH] 1571285 ValueError: too many values to unpack fixed the original error "ValueError: too many values to unpack" (was due to /proc/stat). then the application had problems interpreting /proc/meminfo: "Can't find memory information in /proc/meminfo." I hope, but I'm not 100% sure, that the repairs didn't break the application on kernel 2.4. --- examples/pywmsysmon.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/pywmsysmon.py b/examples/pywmsysmon.py index 543faa7..2fd27f5 100755 --- a/examples/pywmsysmon.py +++ b/examples/pywmsysmon.py @@ -36,7 +36,7 @@ import time import getopt import os -from pywmgeneral import wmdocklib +import wmdocklib width = 64 height = 64 @@ -112,16 +112,28 @@ class PywmSysMon: except IOError, e: sys.stderr.write("Can't open meminfo file: %s.\n" % str(e)) sys.exit(2) - theLine = None + total = used = free = shared = buffers = cached = theLine = None for line in meminfoFile: if line.startswith('Mem:'): theLine = line - if theLine is None: + break + if line.startswith('MemTotal:'): + total = long(line.split()[1]) + if line.startswith('MemFree:'): + free = long(line.split()[1]) + if line.startswith('Buffers:'): + buffers = long(line.split()[1]) + if line.startswith('Cached:'): + cached = long(line.split()[1]) + if free and total: + used = total - free + if theLine is not None: + parts = [long(x) for x in theLine.split()[1]] + total, used, free, shared, buffers, cached = parts[:6] + if None in [total, used, buffers, cached]: sys.stderr.write("Can't find memory information in %s.\n" % self._procMeminfo) sys.exit(4) - parts = [long(x) for x in theLine.split()[1:]] - total, used, free, shared, buffers, cached = parts return (total, used, buffers, cached) def freeMem(self, memData): @@ -145,7 +157,7 @@ class PywmSysMon: sys.exit(2) line = statFile.readline() statFile.close() - cpu, nice, system, idle = [long(x) for x in line.split()[1:]] + cpu, nice, system, idle = [long(x) for x in line.split()[1:]][:4] used = cpu + system if not self._ignoreNice: used += nice