diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-12-27 10:16:42 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-12-27 10:16:42 (GMT) |
commit | 438b534ad0e7522cadba20cd3aec41d02b2bc09b (patch) | |
tree | d8ee75a3b58dc7fdc4593b34c3b85b3c263ba068 /Modules/posixmodule.c | |
parent | 8702d5f33ffb9c55b2372d3cd424b65e783c13ee (diff) | |
download | cpython-438b534ad0e7522cadba20cd3aec41d02b2bc09b.zip cpython-438b534ad0e7522cadba20cd3aec41d02b2bc09b.tar.gz cpython-438b534ad0e7522cadba20cd3aec41d02b2bc09b.tar.bz2 |
Patch #657889: Implement posix.getloadavg.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b8475af..1d8697e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7135,6 +7135,28 @@ win32_startfile(PyObject *self, PyObject *args) } #endif +#ifdef HAVE_GETLOADAVG +PyDoc_STRVAR(posix_getloadavg__doc__, +"getloadavg() -> (float, float, float)\n\n\ +Return the number of processes in the system run queue averaged over\n\ +the last 1, 5, and 15 minutes or raises OSError if the load average\n\ +was unobtainable"); + +static PyObject * +posix_getloadavg(PyObject *self, PyObject *args) +{ + double loadavg[3]; + if (!PyArg_ParseTuple(args, ":getloadavg")) + return NULL; + if (getloadavg(loadavg, 3)!=3) { + PyErr_SetString(PyExc_OSError, "Load averages are unobtainable"); + return NULL; + } else + return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]); +} +#endif + + static PyMethodDef posix_methods[] = { {"access", posix_access, METH_VARARGS, posix_access__doc__}, #ifdef HAVE_TTYNAME @@ -7409,6 +7431,9 @@ static PyMethodDef posix_methods[] = { #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, #endif +#ifdef HAVE_GETLOADAVG + {"getloadavg", posix_getloadavg, METH_VARARGS, posix_getloadavg__doc__}, +#endif {NULL, NULL} /* Sentinel */ }; |