Patch #657889: Implement posix.getloadavg.

This commit is contained in:
Martin v. Löwis 2002-12-27 10:16:42 +00:00
parent 8702d5f33f
commit 438b534ad0
5 changed files with 44 additions and 5 deletions

View File

@ -1431,6 +1431,14 @@ This can be used to determine the set of names known to the system.
Availability: \UNIX.
\end{datadesc}
\begin{funcdesc}{getloadavg}{}
Return the number of processes in the system run queue averaged over
the last 1, 5, and 15 minutes or raises OSError if the load average
was unobtainable.
\versionadded{2.3}
\end{funcdesc}
\begin{funcdesc}{sysconf}{name}
Return integer-valued system configuration values.
If the configuration value specified by \var{name} isn't defined,

View File

@ -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
@ -7408,6 +7430,9 @@ static PyMethodDef posix_methods[] = {
{"abort", posix_abort, METH_VARARGS, posix_abort__doc__},
#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 */
};

8
configure vendored
View File

@ -1,5 +1,5 @@
#! /bin/sh
# From configure.in Revision: 1.377 .
# From configure.in Revision: 1.378 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.53 for python 2.3.
#
@ -12007,11 +12007,13 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
for ac_func in alarm chown clock confstr ctermid execv \
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
getpriority getpwent getwd \
hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
mremap nice pathconf pause plock poll pthread_init \
putenv readlink \
@ -12019,7 +12021,7 @@ for ac_func in alarm chown clock confstr ctermid execv \
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
sigaction siginterrupt sigrelse strftime strptime \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
truncate uname unsetenv utimes waitpid wcscoll _getpty getpriority
truncate uname unsetenv utimes waitpid wcscoll _getpty
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@ -1762,7 +1762,8 @@ AC_MSG_RESULT(MACHDEP_OBJS)
# checks for library functions
AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
getpriority getpwent getwd \
hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
mremap nice pathconf pause plock poll pthread_init \
putenv readlink \
@ -1770,7 +1771,7 @@ AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
sigaction siginterrupt sigrelse strftime strptime \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
truncate uname unsetenv utimes waitpid wcscoll _getpty getpriority)
truncate uname unsetenv utimes waitpid wcscoll _getpty)
# For some functions, having a definition is not sufficient, since
# we want to take their address.

View File

@ -159,6 +159,9 @@
/* Define this if you have the 6-arg version of gethostbyname_r(). */
#undef HAVE_GETHOSTBYNAME_R_6_ARG
/* Define to 1 if you have the `getloadavg' function. */
#undef HAVE_GETLOADAVG
/* Define to 1 if you have the `getlogin' function. */
#undef HAVE_GETLOGIN