1
0
mirror of https://github.com/gryf/wmdocklib.git synced 2025-12-19 20:38:03 +01:00

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.
This commit is contained in:
mfrasca
2006-10-05 11:25:05 +00:00
parent 7a7f3d9b89
commit fca72de090

View File

@@ -36,7 +36,7 @@ import time
import getopt import getopt
import os import os
from pywmgeneral import wmdocklib import wmdocklib
width = 64 width = 64
height = 64 height = 64
@@ -112,16 +112,28 @@ class PywmSysMon:
except IOError, e: except IOError, e:
sys.stderr.write("Can't open meminfo file: %s.\n" % str(e)) sys.stderr.write("Can't open meminfo file: %s.\n" % str(e))
sys.exit(2) sys.exit(2)
theLine = None total = used = free = shared = buffers = cached = theLine = None
for line in meminfoFile: for line in meminfoFile:
if line.startswith('Mem:'): if line.startswith('Mem:'):
theLine = line 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" % sys.stderr.write("Can't find memory information in %s.\n" %
self._procMeminfo) self._procMeminfo)
sys.exit(4) sys.exit(4)
parts = [long(x) for x in theLine.split()[1:]]
total, used, free, shared, buffers, cached = parts
return (total, used, buffers, cached) return (total, used, buffers, cached)
def freeMem(self, memData): def freeMem(self, memData):
@@ -145,7 +157,7 @@ class PywmSysMon:
sys.exit(2) sys.exit(2)
line = statFile.readline() line = statFile.readline()
statFile.close() 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 used = cpu + system
if not self._ignoreNice: if not self._ignoreNice:
used += nice used += nice