summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-10-21 23:35:56 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2020-10-21 23:35:56 +0000
commit28db82f7a934fbd01ccb724414d1f883ab8435a4 (patch)
tree06d4dabd27fb397ca4df4c4a1e2ef69db798101b
parenta9f9813530c5de0e351c8b652838d00aa1a265df (diff)
downloadpsutil-28db82f7a934fbd01ccb724414d1f883ab8435a4.tar.gz
move RLIMIT_ constants in _psutil_posix.c
-rw-r--r--psutil/__init__.py114
-rw-r--r--psutil/_psbsd.py2
-rw-r--r--psutil/_psutil_linux.c43
-rw-r--r--psutil/_psutil_posix.c83
4 files changed, 161 insertions, 81 deletions
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 2108a40e..9951692b 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -102,44 +102,6 @@ if LINUX:
from ._pslinux import IOPRIO_CLASS_IDLE # NOQA
from ._pslinux import IOPRIO_CLASS_NONE # NOQA
from ._pslinux import IOPRIO_CLASS_RT # NOQA
- # Linux >= 2.6.36
- if _psplatform.HAS_PRLIMIT:
- from ._psutil_linux import RLIM_INFINITY # NOQA
- from ._psutil_linux import RLIMIT_AS # NOQA
- from ._psutil_linux import RLIMIT_CORE # NOQA
- from ._psutil_linux import RLIMIT_CPU # NOQA
- from ._psutil_linux import RLIMIT_DATA # NOQA
- from ._psutil_linux import RLIMIT_FSIZE # NOQA
- from ._psutil_linux import RLIMIT_LOCKS # NOQA
- from ._psutil_linux import RLIMIT_MEMLOCK # NOQA
- from ._psutil_linux import RLIMIT_NOFILE # NOQA
- from ._psutil_linux import RLIMIT_NPROC # NOQA
- from ._psutil_linux import RLIMIT_RSS # NOQA
- from ._psutil_linux import RLIMIT_STACK # NOQA
- # Kinda ugly but considerably faster than using hasattr() and
- # setattr() against the module object (we are at import time:
- # speed matters).
- from . import _psutil_linux
- try:
- RLIMIT_MSGQUEUE = _psutil_linux.RLIMIT_MSGQUEUE
- except AttributeError:
- pass
- try:
- RLIMIT_NICE = _psutil_linux.RLIMIT_NICE
- except AttributeError:
- pass
- try:
- RLIMIT_RTPRIO = _psutil_linux.RLIMIT_RTPRIO
- except AttributeError:
- pass
- try:
- RLIMIT_RTTIME = _psutil_linux.RLIMIT_RTTIME
- except AttributeError:
- pass
- try:
- RLIMIT_SIGPENDING = _psutil_linux.RLIMIT_SIGPENDING
- except AttributeError:
- pass
elif WINDOWS:
from . import _pswindows as _psplatform
@@ -181,6 +143,82 @@ else: # pragma: no cover
raise NotImplementedError('platform %s is not supported' % sys.platform)
+if LINUX or FREEBSD:
+ # Kinda ugly but considerably faster than using hasattr() and
+ # setattr() against the module object (we are at import time:
+ # speed matters).
+ from . import _psutil_posix
+
+ try:
+ RLIM_INFINITY = _psutil_posix.RLIM_INFINITY # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_AS = _psutil_posix.RLIMIT_AS # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_CORE = _psutil_posix.RLIMIT_CORE # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_CPU = _psutil_posix.RLIMIT_CPU # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_DATA = _psutil_posix.RLIMIT_DATA # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_FSIZE = _psutil_posix.RLIMIT_FSIZE # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_LOCKS = _psutil_posix.RLIMIT_LOCKS # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_MEMLOCK = _psutil_posix.RLIMIT_MEMLOCK # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_NOFILE = _psutil_posix.RLIMIT_NOFILE # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_NPROC = _psutil_posix.RLIMIT_NPROC # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_RSS = _psutil_posix.RLIMIT_RSS # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_STACK = _psutil_posix.RLIMIT_STACK # NOQA
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_MSGQUEUE = _psutil_posix.RLIMIT_MSGQUEUE
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_NICE = _psutil_posix.RLIMIT_NICE
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_RTPRIO = _psutil_posix.RLIMIT_RTPRIO
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_RTTIME = _psutil_posix.RLIMIT_RTTIME
+ except AttributeError:
+ pass
+ try:
+ RLIMIT_SIGPENDING = _psutil_posix.RLIMIT_SIGPENDING
+ except AttributeError:
+ pass
+
+
__all__ = [
# exceptions
"Error", "NoSuchProcess", "ZombieProcess", "AccessDenied",
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 428c8bde..aff0e04e 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -34,6 +34,8 @@ from ._compat import which
__extra__all__ = []
+__extra__all__.extend(
+ [x for x in dir(cext_posix) if x.startswith('RLIM') and x.isupper()])
# =====================================================================
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 41547438..4def9692 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -606,7 +606,6 @@ static PyMethodDef mod_methods[] = {
void init_psutil_linux(void)
#endif /* PY_MAJOR_VERSION */
{
- PyObject *v;
#if PY_MAJOR_VERSION >= 3
PyObject *mod = PyModule_Create(&moduledef);
#else
@@ -616,48 +615,6 @@ static PyMethodDef mod_methods[] = {
INITERR;
if (PyModule_AddIntConstant(mod, "version", PSUTIL_VERSION)) INITERR;
-#if PSUTIL_HAVE_PRLIMIT
- if (PyModule_AddIntConstant(mod, "RLIMIT_AS", RLIMIT_AS)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_CORE", RLIMIT_CORE)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_CPU", RLIMIT_CPU)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_DATA", RLIMIT_DATA)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_FSIZE", RLIMIT_FSIZE)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_LOCKS", RLIMIT_LOCKS)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_NOFILE", RLIMIT_NOFILE)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_NPROC", RLIMIT_NPROC)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_RSS", RLIMIT_RSS)) INITERR;
- if (PyModule_AddIntConstant(mod, "RLIMIT_STACK", RLIMIT_STACK)) INITERR;
-
-#if defined(HAVE_LONG_LONG)
- if (sizeof(RLIM_INFINITY) > sizeof(long)) {
- v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
- } else
-#endif
- {
- v = PyLong_FromLong((long) RLIM_INFINITY);
- }
- if (v) {
- PyModule_AddObject(mod, "RLIM_INFINITY", v);
- }
-
-#ifdef RLIMIT_MSGQUEUE
- if (PyModule_AddIntConstant(mod, "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE)) INITERR;
-#endif
-#ifdef RLIMIT_NICE
- if (PyModule_AddIntConstant(mod, "RLIMIT_NICE", RLIMIT_NICE)) INITERR;
-#endif
-#ifdef RLIMIT_RTPRIO
- if (PyModule_AddIntConstant(mod, "RLIMIT_RTPRIO", RLIMIT_RTPRIO)) INITERR;
-#endif
-#ifdef RLIMIT_RTTIME
- if (PyModule_AddIntConstant(mod, "RLIMIT_RTTIME", RLIMIT_RTTIME)) INITERR;
-#endif
-#ifdef RLIMIT_SIGPENDING
- if (PyModule_AddIntConstant(mod, "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING))
- INITERR;
-#endif
-#endif
if (PyModule_AddIntConstant(mod, "DUPLEX_HALF", DUPLEX_HALF)) INITERR;
if (PyModule_AddIntConstant(mod, "DUPLEX_FULL", DUPLEX_FULL)) INITERR;
if (PyModule_AddIntConstant(mod, "DUPLEX_UNKNOWN", DUPLEX_UNKNOWN)) INITERR;
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c
index 1182765d..11befdc6 100644
--- a/psutil/_psutil_posix.c
+++ b/psutil/_psutil_posix.c
@@ -15,6 +15,7 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
+#include <sys/resource.h>
#ifdef PSUTIL_SUNOS10
#include "arch/solaris/v10/ifaddrs.h"
@@ -668,6 +669,88 @@ static PyMethodDef mod_methods[] = {
if (PyModule_AddIntConstant(mod, "AF_LINK", AF_LINK)) INITERR;
#endif
+#if defined(PSUTIL_LINUX) || defined(PSUTIL_FREEBSD)
+ PyObject *v;
+
+#ifdef RLIMIT_AS
+ if (PyModule_AddIntConstant(mod, "RLIMIT_AS", RLIMIT_AS)) INITERR;
+#endif
+
+#ifdef RLIMIT_CORE
+ if (PyModule_AddIntConstant(mod, "RLIMIT_CORE", RLIMIT_CORE)) INITERR;
+#endif
+
+#ifdef RLIMIT_CPU
+ if (PyModule_AddIntConstant(mod, "RLIMIT_CPU", RLIMIT_CPU)) INITERR;
+#endif
+
+#ifdef RLIMIT_DATA
+ if (PyModule_AddIntConstant(mod, "RLIMIT_DATA", RLIMIT_DATA)) INITERR;
+#endif
+
+#ifdef RLIMIT_FSIZE
+ if (PyModule_AddIntConstant(mod, "RLIMIT_FSIZE", RLIMIT_FSIZE)) INITERR;
+#endif
+
+#ifdef RLIMIT_LOCKS
+ if (PyModule_AddIntConstant(mod, "RLIMIT_LOCKS", RLIMIT_LOCKS)) INITERR;
+#endif
+
+#ifdef RLIMIT_MEMLOCK
+ if (PyModule_AddIntConstant(mod, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK)) INITERR;
+#endif
+
+#ifdef RLIMIT_NOFILE
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NOFILE", RLIMIT_NOFILE)) INITERR;
+#endif
+
+#ifdef RLIMIT_NPROC
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NPROC", RLIMIT_NPROC)) INITERR;
+#endif
+
+#ifdef RLIMIT_RSS
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RSS", RLIMIT_RSS)) INITERR;
+#endif
+
+#ifdef RLIMIT_STACK
+ if (PyModule_AddIntConstant(mod, "RLIMIT_STACK", RLIMIT_STACK)) INITERR;
+#endif
+
+// Linux specific
+
+#ifdef RLIMIT_MSGQUEUE
+ if (PyModule_AddIntConstant(mod, "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE)) INITERR;
+#endif
+
+#ifdef RLIMIT_NICE
+ if (PyModule_AddIntConstant(mod, "RLIMIT_NICE", RLIMIT_NICE)) INITERR;
+#endif
+
+#ifdef RLIMIT_RTPRIO
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RTPRIO", RLIMIT_RTPRIO)) INITERR;
+#endif
+
+#ifdef RLIMIT_RTTIME
+ if (PyModule_AddIntConstant(mod, "RLIMIT_RTTIME", RLIMIT_RTTIME)) INITERR;
+#endif
+
+#ifdef RLIMIT_SIGPENDING
+ if (PyModule_AddIntConstant(mod, "RLIMIT_SIGPENDING", RLIMIT_SIGPENDING)) INITERR;
+#endif
+
+#if defined(HAVE_LONG_LONG)
+ if (sizeof(RLIM_INFINITY) > sizeof(long)) {
+ v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
+ } else
+#endif
+ {
+ v = PyLong_FromLong((long) RLIM_INFINITY);
+ }
+ if (v) {
+ PyModule_AddObject(mod, "RLIM_INFINITY", v);
+ }
+#endif // defined(PSUTIL_LINUX) || defined(PSUTIL_FREEBSD)
+
if (mod == NULL)
INITERR;
#if PY_MAJOR_VERSION >= 3