From f72ccfef63aa906ea5c708ec43e1f9c238865472 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 6 Mar 2019 07:58:31 -0800 Subject: basic skeleton, still very far from working --- psutil/__init__.py | 2 +- psutil/_psutil_windows.c | 18 ++++++++++++++++++ psutil/_pswindows.py | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/psutil/__init__.py b/psutil/__init__.py index bd0d5e4d..5b5fab24 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -146,6 +146,7 @@ elif WINDOWS: from ._psutil_windows import NORMAL_PRIORITY_CLASS # NOQA from ._psutil_windows import REALTIME_PRIORITY_CLASS # NOQA from ._pswindows import CONN_DELETE_TCB # NOQA + from ._psutil_windows import WIN_RLIMIT_MEMORY # NOQA elif MACOS: from . import _psosx as _psplatform @@ -893,7 +894,6 @@ class Process(object): else: return self._proc.ionice_set(ioclass, value) - # Linux only if hasattr(_psplatform.Process, "rlimit"): def rlimit(self, resource, limits=None): diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 5c05ac38..32efa3b7 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -50,6 +50,8 @@ #define AF_INET6 23 #endif +#define WIN_RLIMIT_MEMORY 1 + PIP_ADAPTER_ADDRESSES psutil_get_nic_addresses() { @@ -3357,6 +3359,16 @@ psutil_sensors_battery(PyObject *self, PyObject *args) { } +/* + * Get process resource limits. + */ +static PyObject * +psutil_proc_rlimit_get(PyObject *self, PyObject *args) { + QueryInformationJobObject(); + return Py_BuildValue("i", 88); +} + + // ------------------------ Python init --------------------------- static PyMethodDef @@ -3416,6 +3428,8 @@ PsutilMethods[] = { "Return the number of handles opened by process."}, {"proc_memory_maps", psutil_proc_memory_maps, METH_VARARGS, "Return a list of process's memory mappings"}, + {"proc_rlimit_get", psutil_proc_rlimit_get, METH_VARARGS, + "Get process resource limits."}, // --- alternative pinfo interface {"proc_info", psutil_proc_info, METH_VARARGS, @@ -3661,6 +3675,10 @@ void init_psutil_windows(void) PyModule_AddIntConstant( module, "WINDOWS_10", PSUTIL_WINDOWS_10); + // resource limits + PyModule_AddIntConstant( + module, "WIN_RLIMIT_MEMORY", WIN_RLIMIT_MEMORY); + #if PY_MAJOR_VERSION >= 3 return module; #endif diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 9fa14af4..165549cf 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -52,6 +52,8 @@ from ._psutil_windows import HIGH_PRIORITY_CLASS from ._psutil_windows import IDLE_PRIORITY_CLASS from ._psutil_windows import NORMAL_PRIORITY_CLASS from ._psutil_windows import REALTIME_PRIORITY_CLASS +from ._psutil_windows import WIN_RLIMIT_MEMORY + if sys.version_info >= (3, 4): import enum @@ -67,6 +69,7 @@ __extra__all__ = [ "NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS", "CONN_DELETE_TCB", "AF_LINK", + "WIN_RLIMIT_MEMORY", ] @@ -1057,3 +1060,10 @@ class Process(object): ctx_switches = self.oneshot_info()[pinfo_map['ctx_switches']] # only voluntary ctx switches are supported return _common.pctxsw(ctx_switches, 0) + + @wrap_exceptions + def rlimit(self, resource, limits=None): + if limits is None: + return cext.proc_rlimit_get(resource) + else: + raise NotImplementedError # XXX -- cgit v1.2.1