summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-01-11 05:07:27 +0000
committerZac Medico <zmedico@gentoo.org>2009-01-11 05:07:27 +0000
commit8607a39dc9d979713f9434839ed1aef2602276a1 (patch)
treec257710a0c172817331c499da794926921bd2152
parentfeaaa1b24d1bfd473558d90a6047e869a1616718 (diff)
downloadportage-8607a39dc9d979713f9434839ed1aef2602276a1.tar.gz
portage-8607a39dc9d979713f9434839ed1aef2602276a1.tar.bz2
portage-8607a39dc9d979713f9434839ed1aef2602276a1.zip
If necessary, use /proc/loadavg to emulate os.getloadavg().
svn path=/main/trunk/; revision=12422
-rw-r--r--pym/_emerge/__init__.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 30b494065..38f55ecaf 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -8951,6 +8951,29 @@ def create_poll_instance():
return select.poll()
return PollSelectAdapter()
+getloadavg = getattr(os, "getloadavg", None)
+if getloadavg is None:
+ def getloadavg():
+ """
+ Uses /proc/loadavg to emulate os.getloadavg().
+ Raises OSError if the load average was unobtainable.
+ """
+ try:
+ loadavg_str = open('/proc/loadavg').readline()
+ except IOError:
+ # getloadavg() is only supposed to raise OSError, so convert
+ raise OSError('unknown')
+ loadavg_split = loadavg_str.split()
+ if len(loadavg_split) < 3:
+ raise OSError('unknown')
+ loadavg_floats = []
+ for i in xrange(3):
+ try:
+ loadavg_floats.append(float(loadavg_split[i]))
+ except ValueError:
+ raise OSError('unknown')
+ return tuple(loadavg_floats)
+
class PollScheduler(object):
class _sched_iface_class(SlotObject):
@@ -8998,11 +9021,8 @@ class PollScheduler(object):
(max_jobs is True or max_jobs > 1) and \
self._running_job_count() >= 1:
try:
- avg1, avg5, avg15 = os.getloadavg()
- except (AttributeError, OSError), e:
- writemsg("!!! getloadavg() failed: %s\n" % (e,),
- noiselevel=-1)
- del e
+ avg1, avg5, avg15 = getloadavg()
+ except OSError:
return False
if avg1 >= max_load:
@@ -9383,9 +9403,9 @@ class JobStatusDisplay(object):
def _load_avg_str(self):
try:
- avg = os.getloadavg()
- except (AttributeError, OSError), e:
- return str(e)
+ avg = getloadavg()
+ except OSError:
+ return 'unknown'
max_avg = max(avg)