[Python-checkins] python/dist/src/Modules posixmodule.c,2.275,2.276

loewis@users.sourceforge.net loewis@users.sourceforge.net
Fri, 27 Dec 2002 02:16:45 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv24016/Modules

Modified Files:
	posixmodule.c 
Log Message:
Patch #657889: Implement posix.getloadavg.


Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.275
retrieving revision 2.276
diff -C2 -d -r2.275 -r2.276
*** posixmodule.c	13 Dec 2002 18:36:22 -0000	2.275
--- posixmodule.c	27 Dec 2002 10:16:42 -0000	2.276
***************
*** 7136,7139 ****
--- 7136,7161 ----
  #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__},
***************
*** 7409,7412 ****
--- 7431,7437 ----
  #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 */