summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fresource.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/library%2Fresource.html
new repository
Diffstat (limited to 'devdocs/python~3.12/library%2Fresource.html')
-rw-r--r--devdocs/python~3.12/library%2Fresource.html130
1 files changed, 130 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fresource.html b/devdocs/python~3.12/library%2Fresource.html
new file mode 100644
index 00000000..9cc59a72
--- /dev/null
+++ b/devdocs/python~3.12/library%2Fresource.html
@@ -0,0 +1,130 @@
+ <span id="resource-resource-usage-information"></span><h1>resource — Resource usage information</h1> <p>This module provides basic mechanisms for measuring and controlling system resources utilized by a program.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not Emscripten, not WASI.</p> </div> <p>Symbolic constants are used to specify particular system resources and to request usage information about either the current process or its children.</p> <p>An <a class="reference internal" href="exceptions#OSError" title="OSError"><code>OSError</code></a> is raised on syscall failure.</p> <dl class="py exception"> <dt class="sig sig-object py" id="resource.error">
+<code>exception resource.error</code> </dt> <dd>
+<p>A deprecated alias of <a class="reference internal" href="exceptions#OSError" title="OSError"><code>OSError</code></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>Following <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a>, this class was made an alias of <a class="reference internal" href="exceptions#OSError" title="OSError"><code>OSError</code></a>.</p> </div> </dd>
+</dl> <section id="resource-limits"> <h2>Resource Limits</h2> <p>Resources usage can be limited using the <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code>setrlimit()</code></a> function described below. Each resource is controlled by a pair of limits: a soft limit and a hard limit. The soft limit is the current limit, and may be lowered or raised by a process over time. The soft limit can never exceed the hard limit. The hard limit can be lowered to any value greater than the soft limit, but not raised. (Only processes with the effective UID of the super-user can raise a hard limit.)</p> <p>The specific resources that can be limited are system dependent. They are described in the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> man page. The resources listed below are supported when the underlying operating system supports them; resources which cannot be checked or controlled by the operating system are not defined in this module for those platforms.</p> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIM_INFINITY">
+<code>resource.RLIM_INFINITY</code> </dt> <dd>
+<p>Constant used to represent the limit for an unlimited resource.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="resource.getrlimit">
+<code>resource.getrlimit(resource)</code> </dt> <dd>
+<p>Returns a tuple <code>(soft, hard)</code> with the current soft and hard limits of <em>resource</em>. Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if an invalid resource is specified, or <a class="reference internal" href="#resource.error" title="resource.error"><code>error</code></a> if the underlying system call fails unexpectedly.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="resource.setrlimit">
+<code>resource.setrlimit(resource, limits)</code> </dt> <dd>
+<p>Sets new limits of consumption of <em>resource</em>. The <em>limits</em> argument must be a tuple <code>(soft, hard)</code> of two integers describing the new limits. A value of <a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code>RLIM_INFINITY</code></a> can be used to request a limit that is unlimited.</p> <p>Raises <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if an invalid resource is specified, if the new soft limit exceeds the hard limit, or if a process tries to raise its hard limit. Specifying a limit of <a class="reference internal" href="#resource.RLIM_INFINITY" title="resource.RLIM_INFINITY"><code>RLIM_INFINITY</code></a> when the hard or system limit for that resource is not unlimited will result in a <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a>. A process with the effective UID of super-user can request any valid limit value, including unlimited, but <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> will still be raised if the requested limit exceeds the system imposed limit.</p> <p><code>setrlimit</code> may also raise <a class="reference internal" href="#resource.error" title="resource.error"><code>error</code></a> if the underlying system call fails.</p> <p>VxWorks only supports setting <a class="reference internal" href="#resource.RLIMIT_NOFILE" title="resource.RLIMIT_NOFILE"><code>RLIMIT_NOFILE</code></a>.</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>resource.setrlimit</code> with arguments <code>resource</code>, <code>limits</code>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="resource.prlimit">
+<code>resource.prlimit(pid, resource[, limits])</code> </dt> <dd>
+<p>Combines <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code>setrlimit()</code></a> and <a class="reference internal" href="#resource.getrlimit" title="resource.getrlimit"><code>getrlimit()</code></a> in one function and supports to get and set the resources limits of an arbitrary process. If <em>pid</em> is 0, then the call applies to the current process. <em>resource</em> and <em>limits</em> have the same meaning as in <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code>setrlimit()</code></a>, except that <em>limits</em> is optional.</p> <p>When <em>limits</em> is not given the function returns the <em>resource</em> limit of the process <em>pid</em>. When <em>limits</em> is given the <em>resource</em> limit of the process is set and the former resource limit is returned.</p> <p>Raises <a class="reference internal" href="exceptions#ProcessLookupError" title="ProcessLookupError"><code>ProcessLookupError</code></a> when <em>pid</em> can’t be found and <a class="reference internal" href="exceptions#PermissionError" title="PermissionError"><code>PermissionError</code></a> when the user doesn’t have <code>CAP_SYS_RESOURCE</code> for the process.</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>resource.prlimit</code> with arguments <code>pid</code>, <code>resource</code>, <code>limits</code>.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.36 with glibc &gt;= 2.13.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <p>These symbols define resources whose consumption can be controlled using the <a class="reference internal" href="#resource.setrlimit" title="resource.setrlimit"><code>setrlimit()</code></a> and <a class="reference internal" href="#resource.getrlimit" title="resource.getrlimit"><code>getrlimit()</code></a> functions described below. The values of these symbols are exactly the constants used by C programs.</p> <p>The Unix man page for <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrlimit(2)">getrlimit(2)</a></em> lists the available resources. Note that not all systems use the same symbol or same value to denote the same resource. This module does not attempt to mask platform differences — symbols not defined for a platform will not be available from this module on that platform.</p> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_CORE">
+<code>resource.RLIMIT_CORE</code> </dt> <dd>
+<p>The maximum size (in bytes) of a core file that the current process can create. This may result in the creation of a partial core file if a larger core would be required to contain the entire process image.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_CPU">
+<code>resource.RLIMIT_CPU</code> </dt> <dd>
+<p>The maximum amount of processor time (in seconds) that a process can use. If this limit is exceeded, a <code>SIGXCPU</code> signal is sent to the process. (See the <a class="reference internal" href="signal#module-signal" title="signal: Set handlers for asynchronous events."><code>signal</code></a> module documentation for information about how to catch this signal and do something useful, e.g. flush open files to disk.)</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_FSIZE">
+<code>resource.RLIMIT_FSIZE</code> </dt> <dd>
+<p>The maximum size of a file which the process may create.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_DATA">
+<code>resource.RLIMIT_DATA</code> </dt> <dd>
+<p>The maximum size (in bytes) of the process’s heap.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_STACK">
+<code>resource.RLIMIT_STACK</code> </dt> <dd>
+<p>The maximum size (in bytes) of the call stack for the current process. This only affects the stack of the main thread in a multi-threaded process.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_RSS">
+<code>resource.RLIMIT_RSS</code> </dt> <dd>
+<p>The maximum resident set size that should be made available to the process.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_NPROC">
+<code>resource.RLIMIT_NPROC</code> </dt> <dd>
+<p>The maximum number of processes the current process may create.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_NOFILE">
+<code>resource.RLIMIT_NOFILE</code> </dt> <dd>
+<p>The maximum number of open file descriptors for the current process.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_OFILE">
+<code>resource.RLIMIT_OFILE</code> </dt> <dd>
+<p>The BSD name for <a class="reference internal" href="#resource.RLIMIT_NOFILE" title="resource.RLIMIT_NOFILE"><code>RLIMIT_NOFILE</code></a>.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_MEMLOCK">
+<code>resource.RLIMIT_MEMLOCK</code> </dt> <dd>
+<p>The maximum address space which may be locked in memory.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_VMEM">
+<code>resource.RLIMIT_VMEM</code> </dt> <dd>
+<p>The largest area of mapped memory which the process may occupy.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_AS">
+<code>resource.RLIMIT_AS</code> </dt> <dd>
+<p>The maximum area (in bytes) of address space which may be taken by the process.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_MSGQUEUE">
+<code>resource.RLIMIT_MSGQUEUE</code> </dt> <dd>
+<p>The number of bytes that can be allocated for POSIX message queues.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.8.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_NICE">
+<code>resource.RLIMIT_NICE</code> </dt> <dd>
+<p>The ceiling for the process’s nice level (calculated as 20 - rlim_cur).</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.12.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_RTPRIO">
+<code>resource.RLIMIT_RTPRIO</code> </dt> <dd>
+<p>The ceiling of the real-time priority.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.12.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_RTTIME">
+<code>resource.RLIMIT_RTTIME</code> </dt> <dd>
+<p>The time limit (in microseconds) on CPU time that a process can spend under real-time scheduling without making a blocking syscall.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.25.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_SIGPENDING">
+<code>resource.RLIMIT_SIGPENDING</code> </dt> <dd>
+<p>The number of signals which the process may queue.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.8.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_SBSIZE">
+<code>resource.RLIMIT_SBSIZE</code> </dt> <dd>
+<p>The maximum size (in bytes) of socket buffer usage for this user. This limits the amount of network memory, and hence the amount of mbufs, that this user may hold at any time.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_SWAP">
+<code>resource.RLIMIT_SWAP</code> </dt> <dd>
+<p>The maximum size (in bytes) of the swap space that may be reserved or used by all of this user id’s processes. This limit is enforced only if bit 1 of the vm.overcommit sysctl is set. Please see <a class="reference external" href="https://man.freebsd.org/cgi/man.cgi?query=tuning&amp;sektion=7">tuning(7)</a> for a complete description of this sysctl.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_NPTS">
+<code>resource.RLIMIT_NPTS</code> </dt> <dd>
+<p>The maximum number of pseudo-terminals created by this user id.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RLIMIT_KQUEUES">
+<code>resource.RLIMIT_KQUEUES</code> </dt> <dd>
+<p>The maximum number of kqueues this user id is allowed to create.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD &gt;= 11.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> </section> <section id="resource-usage"> <h2>Resource Usage</h2> <p>These functions are used to retrieve resource usage information:</p> <dl class="py function"> <dt class="sig sig-object py" id="resource.getrusage">
+<code>resource.getrusage(who)</code> </dt> <dd>
+<p>This function returns an object that describes the resources consumed by either the current process or its children, as specified by the <em>who</em> parameter. The <em>who</em> parameter should be specified using one of the <code>RUSAGE_*</code> constants described below.</p> <p>A simple example:</p> <pre data-language="python">from resource import *
+import time
+
+# a non CPU-bound task
+time.sleep(3)
+print(getrusage(RUSAGE_SELF))
+
+# a CPU-bound task
+for i in range(10 ** 8):
+ _ = 1 + 1
+print(getrusage(RUSAGE_SELF))
+</pre> <p>The fields of the return value each describe how a particular system resource has been used, e.g. amount of time spent running is user mode or number of times the process was swapped out of main memory. Some values are dependent on the clock tick internal, e.g. the amount of memory the process is using.</p> <p>For backward compatibility, the return value is also accessible as a tuple of 16 elements.</p> <p>The fields <code>ru_utime</code> and <code>ru_stime</code> of the return value are floating point values representing the amount of time spent executing in user mode and the amount of time spent executing in system mode, respectively. The remaining values are integers. Consult the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/getrusage(2)">getrusage(2)</a></em> man page for detailed information about these values. A brief summary is presented here:</p> <table class="docutils align-default"> <thead> <tr>
+<th class="head"><p>Index</p></th> <th class="head"><p>Field</p></th> <th class="head"><p>Resource</p></th> </tr> </thead> <tr>
+<td><p><code>0</code></p></td> <td><p><code>ru_utime</code></p></td> <td><p>time in user mode (float seconds)</p></td> </tr> <tr>
+<td><p><code>1</code></p></td> <td><p><code>ru_stime</code></p></td> <td><p>time in system mode (float seconds)</p></td> </tr> <tr>
+<td><p><code>2</code></p></td> <td><p><code>ru_maxrss</code></p></td> <td><p>maximum resident set size</p></td> </tr> <tr>
+<td><p><code>3</code></p></td> <td><p><code>ru_ixrss</code></p></td> <td><p>shared memory size</p></td> </tr> <tr>
+<td><p><code>4</code></p></td> <td><p><code>ru_idrss</code></p></td> <td><p>unshared memory size</p></td> </tr> <tr>
+<td><p><code>5</code></p></td> <td><p><code>ru_isrss</code></p></td> <td><p>unshared stack size</p></td> </tr> <tr>
+<td><p><code>6</code></p></td> <td><p><code>ru_minflt</code></p></td> <td><p>page faults not requiring I/O</p></td> </tr> <tr>
+<td><p><code>7</code></p></td> <td><p><code>ru_majflt</code></p></td> <td><p>page faults requiring I/O</p></td> </tr> <tr>
+<td><p><code>8</code></p></td> <td><p><code>ru_nswap</code></p></td> <td><p>number of swap outs</p></td> </tr> <tr>
+<td><p><code>9</code></p></td> <td><p><code>ru_inblock</code></p></td> <td><p>block input operations</p></td> </tr> <tr>
+<td><p><code>10</code></p></td> <td><p><code>ru_oublock</code></p></td> <td><p>block output operations</p></td> </tr> <tr>
+<td><p><code>11</code></p></td> <td><p><code>ru_msgsnd</code></p></td> <td><p>messages sent</p></td> </tr> <tr>
+<td><p><code>12</code></p></td> <td><p><code>ru_msgrcv</code></p></td> <td><p>messages received</p></td> </tr> <tr>
+<td><p><code>13</code></p></td> <td><p><code>ru_nsignals</code></p></td> <td><p>signals received</p></td> </tr> <tr>
+<td><p><code>14</code></p></td> <td><p><code>ru_nvcsw</code></p></td> <td><p>voluntary context switches</p></td> </tr> <tr>
+<td><p><code>15</code></p></td> <td><p><code>ru_nivcsw</code></p></td> <td><p>involuntary context switches</p></td> </tr> </table> <p>This function will raise a <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> if an invalid <em>who</em> parameter is specified. It may also raise <a class="reference internal" href="#resource.error" title="resource.error"><code>error</code></a> exception in unusual circumstances.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="resource.getpagesize">
+<code>resource.getpagesize()</code> </dt> <dd>
+<p>Returns the number of bytes in a system page. (This need not be the same as the hardware page size.)</p> </dd>
+</dl> <p>The following <code>RUSAGE_*</code> symbols are passed to the <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code>getrusage()</code></a> function to specify which processes information should be provided for.</p> <dl class="py data"> <dt class="sig sig-object py" id="resource.RUSAGE_SELF">
+<code>resource.RUSAGE_SELF</code> </dt> <dd>
+<p>Pass to <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code>getrusage()</code></a> to request resources consumed by the calling process, which is the sum of resources used by all threads in the process.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RUSAGE_CHILDREN">
+<code>resource.RUSAGE_CHILDREN</code> </dt> <dd>
+<p>Pass to <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code>getrusage()</code></a> to request resources consumed by child processes of the calling process which have been terminated and waited for.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RUSAGE_BOTH">
+<code>resource.RUSAGE_BOTH</code> </dt> <dd>
+<p>Pass to <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code>getrusage()</code></a> to request resources consumed by both the current process and child processes. May not be available on all systems.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="resource.RUSAGE_THREAD">
+<code>resource.RUSAGE_THREAD</code> </dt> <dd>
+<p>Pass to <a class="reference internal" href="#resource.getrusage" title="resource.getrusage"><code>getrusage()</code></a> to request resources consumed by the current thread. May not be available on all systems.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
+</dl> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/resource.html" class="_attribution-link">https://docs.python.org/3.12/library/resource.html</a>
+ </p>
+</div>