]> granicus.if.org Git - python/commitdiff
Issue #10440: Support RUSAGE_THREAD as a constant in the resource module.
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 17 Nov 2010 16:19:35 +0000 (16:19 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 17 Nov 2010 16:19:35 +0000 (16:19 +0000)
Patch by Robert Collins.

Doc/library/resource.rst
Lib/test/test_resource.py
Misc/NEWS
Modules/resource.c

index 602bd4430974835da519423d8d54dd3f773ea551..c16b01301eb18a22f299941d4841f992992c3377 100644 (file)
@@ -217,14 +217,14 @@ function to specify which processes information should be provided for.
 
 .. data:: RUSAGE_SELF
 
-   :const:`RUSAGE_SELF` should be used to request information pertaining only to
-   the process itself.
+   Pass to :func:`getrusage` to request resources consumed by the calling
+   process, which is the sum of resources used by all threads in the process.
 
 
 .. data:: RUSAGE_CHILDREN
 
-   Pass to :func:`getrusage` to request resource information for child processes of
-   the calling process.
+   Pass to :func:`getrusage` to request resources consumed by child processes
+   of the calling process which have been terminated and waited for.
 
 
 .. data:: RUSAGE_BOTH
@@ -232,3 +232,10 @@ function to specify which processes information should be provided for.
    Pass to :func:`getrusage` to request resources consumed by both the current
    process and child processes.  May not be available on all systems.
 
+
+.. data:: RUSAGE_THREAD
+
+   Pass to :func:`getrusage` to request resources consumed by the current
+   thread.  May not be available on all systems.
+
+   .. versionadded:: 3.2
index 454634922b5207cd0f64cc616a20ac3fa82f1995..3c9b62070268e256496b87b284ab8dd4f62b7273 100644 (file)
@@ -102,6 +102,10 @@ class ResourceTest(unittest.TestCase):
             usageboth = resource.getrusage(resource.RUSAGE_BOTH)
         except (ValueError, AttributeError):
             pass
+        try:
+            usage_thread = resource.getrusage(resource.RUSAGE_THREAD)
+        except (ValueError, AttributeError):
+            pass
 
 def test_main(verbose=None):
     support.run_unittest(ResourceTest)
index f1332ba06945eed6dc420041cc67180e9daf7c32..5580333fae3a3b383ec8cc95ee520db966ffb1e5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10440: Support RUSAGE_THREAD as a constant in the resource module.
+  Patch by Robert Collins.
+
 - Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
   rather than strings.
 
index 6d8bd579c59c1875d79e0da14083b7cf0a136309..450f08ccc6bec2fbaefc55570fe6fac6ab8c9a6e 100644 (file)
@@ -325,6 +325,10 @@ PyInit_resource(void)
     PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH);
 #endif
 
+#ifdef RUSAGE_THREAD
+    PyModule_AddIntConstant(m, "RUSAGE_THREAD", RUSAGE_THREAD);
+#endif
+
 #if defined(HAVE_LONG_LONG)
     if (sizeof(RLIM_INFINITY) > sizeof(long)) {
         v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);