6423 lines
705 KiB
HTML
6423 lines
705 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<meta property="og:title" content="os — Miscellaneous operating system interfaces" />
|
||
<meta property="og:type" content="website" />
|
||
<meta property="og:url" content="https://docs.python.org/3/library/os.html" />
|
||
<meta property="og:site_name" content="Python documentation" />
|
||
<meta property="og:description" content="Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, s..." />
|
||
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
|
||
<meta property="og:image:alt" content="Python documentation" />
|
||
<meta name="description" content="Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, s..." />
|
||
<meta property="og:image:width" content="200">
|
||
<meta property="og:image:height" content="200">
|
||
<meta name="theme-color" content="#3776ab">
|
||
|
||
<title>os — Miscellaneous operating system interfaces — Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
|
||
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
|
||
|
||
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="Search within Python 3.13.3 documentation"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="About these documents" href="../about.html" />
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
||
<link rel="next" title="io — Core tools for working with streams" href="io.html" />
|
||
<link rel="prev" title="Generic Operating System Services" href="allos.html" />
|
||
|
||
<link rel="canonical" href="https://docs.python.org/3/library/os.html">
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
<script type="text/javascript" src="../_static/search-focus.js"></script>
|
||
<script type="text/javascript" src="../_static/themetoggle.js"></script>
|
||
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
|
||
<meta name="readthedocs-addons-api-version" content="1">
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<nav class="nav-content" role="navigation">
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<span class="nav-items-wrapper">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Python logo"/>
|
||
</a>
|
||
<span class="version_switcher_placeholder"></span>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
|
||
</svg>
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
|
||
<input type="submit" value="Go"/>
|
||
</form>
|
||
</span>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label>
|
||
<div>
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> — Miscellaneous operating system interfaces</a><ul>
|
||
<li><a class="reference internal" href="#file-names-command-line-arguments-and-environment-variables">File Names, Command Line Arguments, and Environment Variables</a></li>
|
||
<li><a class="reference internal" href="#python-utf-8-mode">Python UTF-8 Mode</a></li>
|
||
<li><a class="reference internal" href="#process-parameters">Process Parameters</a></li>
|
||
<li><a class="reference internal" href="#file-object-creation">File Object Creation</a></li>
|
||
<li><a class="reference internal" href="#file-descriptor-operations">File Descriptor Operations</a><ul>
|
||
<li><a class="reference internal" href="#querying-the-size-of-a-terminal">Querying the size of a terminal</a></li>
|
||
<li><a class="reference internal" href="#inheritance-of-file-descriptors">Inheritance of File Descriptors</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#files-and-directories">Files and Directories</a><ul>
|
||
<li><a class="reference internal" href="#timer-file-descriptors">Timer File Descriptors</a></li>
|
||
<li><a class="reference internal" href="#linux-extended-attributes">Linux extended attributes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#process-management">Process Management</a></li>
|
||
<li><a class="reference internal" href="#interface-to-the-scheduler">Interface to the scheduler</a></li>
|
||
<li><a class="reference internal" href="#miscellaneous-system-information">Miscellaneous System Information</a></li>
|
||
<li><a class="reference internal" href="#random-numbers">Random numbers</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="allos.html"
|
||
title="previous chapter">Generic Operating System Services</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="io.html"
|
||
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code> — Core tools for working with streams</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">Report a Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/main/Doc/library/os.rst"
|
||
rel="nofollow">Show Source
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="io.html" title="io — Core tools for working with streams"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="allos.html" title="Generic Operating System Services"
|
||
accesskey="P">previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.3 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">Generic Operating System Services</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> — Miscellaneous operating system interfaces</a></li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
<li class="right">
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label> |</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-os">
|
||
<span id="os-miscellaneous-operating-system-interfaces"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> — Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Link to this heading">¶</a></h1>
|
||
<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Lib/os.py">Lib/os.py</a></p>
|
||
<hr class="docutils" />
|
||
<p>This module provides a portable way of using operating system dependent
|
||
functionality. If you just want to read or write a file see <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, if
|
||
you want to manipulate paths, see the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> module, and if you want to
|
||
read all the lines in all the files on the command line see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code></a>
|
||
module. For creating temporary files and directories see the <a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code></a>
|
||
module, and for high-level file and directory handling see the <a class="reference internal" href="shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a>
|
||
module.</p>
|
||
<p>Notes on the availability of these functions:</p>
|
||
<ul class="simple">
|
||
<li><p>The design of all built-in operating system dependent modules of Python is
|
||
such that as long as the same functionality is available, it uses the same
|
||
interface; for example, the function <code class="docutils literal notranslate"><span class="pre">os.stat(path)</span></code> returns stat
|
||
information about <em>path</em> in the same format (which happens to have originated
|
||
with the POSIX interface).</p></li>
|
||
<li><p>Extensions peculiar to a particular operating system are also available
|
||
through the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module, but using them is of course a threat to
|
||
portability.</p></li>
|
||
<li><p>All functions accepting path or file names accept both bytes and string
|
||
objects, and result in an object of the same type, if a path or file name is
|
||
returned.</p></li>
|
||
<li><p>On VxWorks, os.popen, os.fork, os.execv and os.spawn*p* are not supported.</p></li>
|
||
<li><p>On WebAssembly platforms, Android and iOS, large parts of the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module are
|
||
not available or behave differently. APIs related to processes (e.g.
|
||
<a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a>, <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>) and resources (e.g. <a class="reference internal" href="#os.nice" title="os.nice"><code class="xref py py-func docutils literal notranslate"><span class="pre">nice()</span></code></a>)
|
||
are not available. Others like <a class="reference internal" href="#os.getuid" title="os.getuid"><code class="xref py py-func docutils literal notranslate"><span class="pre">getuid()</span></code></a> and <a class="reference internal" href="#os.getpid" title="os.getpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpid()</span></code></a> are
|
||
emulated or stubs. WebAssembly platforms also lack support for signals (e.g.
|
||
<a class="reference internal" href="#os.kill" title="os.kill"><code class="xref py py-func docutils literal notranslate"><span class="pre">kill()</span></code></a>, <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>).</p></li>
|
||
</ul>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>All functions in this module raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> (or subclasses thereof) in
|
||
the case of invalid or inaccessible file names and paths, or other arguments
|
||
that have the correct type, but are not accepted by the operating system.</p>
|
||
</div>
|
||
<dl class="py exception">
|
||
<dt class="sig sig-object py" id="os.error">
|
||
<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">error</span></span><a class="headerlink" href="#os.error" title="Link to this definition">¶</a></dt>
|
||
<dd><p>An alias for the built-in <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.name">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#os.name" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The name of the operating system dependent module imported. The following
|
||
names have currently been registered: <code class="docutils literal notranslate"><span class="pre">'posix'</span></code>, <code class="docutils literal notranslate"><span class="pre">'nt'</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">'java'</span></code>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> has a finer granularity. <a class="reference internal" href="#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.uname()</span></code></a> gives
|
||
system-dependent version information.</p>
|
||
<p>The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> module provides detailed checks for the
|
||
system’s identity.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<section id="file-names-command-line-arguments-and-environment-variables">
|
||
<span id="filesystem-encoding"></span><span id="os-filenames"></span><h2>File Names, Command Line Arguments, and Environment Variables<a class="headerlink" href="#file-names-command-line-arguments-and-environment-variables" title="Link to this heading">¶</a></h2>
|
||
<p>In Python, file names, command line arguments, and environment variables are
|
||
represented using the string type. On some systems, decoding these strings to
|
||
and from bytes is necessary before passing them to the operating system. Python
|
||
uses the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> to perform this
|
||
conversion (see <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>).</p>
|
||
<p>The <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a> are configured at Python
|
||
startup by the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> function: see
|
||
<a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_encoding</span></code></a> and
|
||
<a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_errors</span></code></a> members of <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.1: </span>On some systems, conversion using the file system encoding may fail. In this
|
||
case, Python uses the <a class="reference internal" href="codecs.html#surrogateescape"><span class="std std-ref">surrogateescape encoding error handler</span></a>, which means that undecodable bytes are replaced by a
|
||
Unicode character U+DC<em>xx</em> on decoding, and these are again
|
||
translated to the original byte on encoding.</p>
|
||
</div>
|
||
<p>The <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">file system encoding</span></a> must
|
||
guarantee to successfully decode all bytes below 128. If the file system
|
||
encoding fails to provide this guarantee, API functions can raise
|
||
<a class="reference internal" href="exceptions.html#UnicodeError" title="UnicodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeError</span></code></a>.</p>
|
||
<p>See also the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>.</p>
|
||
</section>
|
||
<section id="python-utf-8-mode">
|
||
<span id="utf8-mode"></span><h2>Python UTF-8 Mode<a class="headerlink" href="#python-utf-8-mode" title="Link to this heading">¶</a></h2>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7: </span>See <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0540/"><strong>PEP 540</strong></a> for more details.</p>
|
||
</div>
|
||
<p>The Python UTF-8 Mode ignores the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> and forces the usage
|
||
of the UTF-8 encoding:</p>
|
||
<ul class="simple">
|
||
<li><p>Use UTF-8 as the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding</span></a>.</p></li>
|
||
<li><p><a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code>.</p></li>
|
||
<li><p><a class="reference internal" href="locale.html#locale.getpreferredencoding" title="locale.getpreferredencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getpreferredencoding()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> (the <em>do_setlocale</em>
|
||
argument has no effect).</p></li>
|
||
<li><p><a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>, and <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> all use
|
||
UTF-8 as their text encoding, with the <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>
|
||
<a class="reference internal" href="codecs.html#error-handlers"><span class="std std-ref">error handler</span></a> being enabled for <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>
|
||
and <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> (<a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> continues to use
|
||
<code class="docutils literal notranslate"><span class="pre">backslashreplace</span></code> as it does in the default locale-aware mode)</p></li>
|
||
<li><p>On Unix, <a class="reference internal" href="#os.device_encoding" title="os.device_encoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.device_encoding()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code> rather than the
|
||
device encoding.</p></li>
|
||
</ul>
|
||
<p>Note that the standard stream settings in UTF-8 mode can be overridden by
|
||
<span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONIOENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONIOENCODING</span></code></a> (just as they can be in the default locale-aware
|
||
mode).</p>
|
||
<p>As a consequence of the changes in those lower level APIs, other higher
|
||
level APIs also exhibit different default behaviours:</p>
|
||
<ul class="simple">
|
||
<li><p>Command line arguments, environment variables and filenames are decoded
|
||
to text using the UTF-8 encoding.</p></li>
|
||
<li><p><a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> and <a class="reference internal" href="#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> use the UTF-8 encoding.</p></li>
|
||
<li><p><a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, <a class="reference internal" href="io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a>, and <a class="reference internal" href="codecs.html#codecs.open" title="codecs.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.open()</span></code></a> use the UTF-8
|
||
encoding by default. However, they still use the strict error handler by
|
||
default so that attempting to open a binary file in text mode is likely
|
||
to raise an exception rather than producing nonsense data.</p></li>
|
||
</ul>
|
||
<p>The <a class="reference internal" href="#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is enabled if the LC_CTYPE locale is
|
||
<code class="docutils literal notranslate"><span class="pre">C</span></code> or <code class="docutils literal notranslate"><span class="pre">POSIX</span></code> at Python startup (see the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a>
|
||
function).</p>
|
||
<p>It can be enabled or disabled using the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8</span></code></a> command line
|
||
option and the <span class="target" id="index-2"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> environment variable.</p>
|
||
<p>If the <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> environment variable is not set at all, then the
|
||
interpreter defaults to using the current locale settings, <em>unless</em> the current
|
||
locale is identified as a legacy ASCII-based locale (as described for
|
||
<span class="target" id="index-4"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCOERCECLOCALE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCOERCECLOCALE</span></code></a>), and locale coercion is either disabled or
|
||
fails. In such legacy locales, the interpreter will default to enabling UTF-8
|
||
mode unless explicitly instructed not to do so.</p>
|
||
<p>The Python UTF-8 Mode can only be enabled at the Python startup. Its value
|
||
can be read from <a class="reference internal" href="sys.html#sys.flags" title="sys.flags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.flags.utf8_mode</span></code></a>.</p>
|
||
<p>See also the <a class="reference internal" href="../using/windows.html#win-utf8-mode"><span class="std std-ref">UTF-8 mode on Windows</span></a>
|
||
and the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0686/"><strong>PEP 686</strong></a></dt><dd><p>Python 3.15 will make <a class="reference internal" href="#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> default.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="process-parameters">
|
||
<span id="os-procinfo"></span><h2>Process Parameters<a class="headerlink" href="#process-parameters" title="Link to this heading">¶</a></h2>
|
||
<p>These functions and data items provide information and operate on the current
|
||
process and user.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.ctermid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">ctermid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.ctermid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the filename corresponding to the controlling terminal of the process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.environ">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">environ</span></span><a class="headerlink" href="#os.environ" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A <a class="reference internal" href="../glossary.html#term-mapping"><span class="xref std std-term">mapping</span></a> object where keys and values are strings that represent
|
||
the process environment. For example, <code class="docutils literal notranslate"><span class="pre">environ['HOME']</span></code> is the pathname
|
||
of your home directory (on some platforms), and is equivalent to
|
||
<code class="docutils literal notranslate"><span class="pre">getenv("HOME")</span></code> in C.</p>
|
||
<p>This mapping is captured the first time the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module is imported,
|
||
typically during Python startup as part of processing <code class="file docutils literal notranslate"><span class="pre">site.py</span></code>. Changes
|
||
to the environment made after this time are not reflected in <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>,
|
||
except for changes made by modifying <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> directly.</p>
|
||
<p>This mapping may be used to modify the environment as well as query the
|
||
environment. <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">putenv()</span></code></a> will be called automatically when the mapping
|
||
is modified.</p>
|
||
<p>On Unix, keys and values use <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a> and
|
||
<code class="docutils literal notranslate"><span class="pre">'surrogateescape'</span></code> error handler. Use <a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">environb</span></code></a> if you would like
|
||
to use a different encoding.</p>
|
||
<p>On Windows, the keys are converted to uppercase. This also applies when
|
||
getting, setting, or deleting an item. For example,
|
||
<code class="docutils literal notranslate"><span class="pre">environ['monty']</span> <span class="pre">=</span> <span class="pre">'python'</span></code> maps the key <code class="docutils literal notranslate"><span class="pre">'MONTY'</span></code> to the value
|
||
<code class="docutils literal notranslate"><span class="pre">'python'</span></code>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Calling <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">putenv()</span></code></a> directly does not change <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>, so it’s better
|
||
to modify <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On some platforms, including FreeBSD and macOS, setting <code class="docutils literal notranslate"><span class="pre">environ</span></code> may
|
||
cause memory leaks. Refer to the system documentation for
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">putenv()</span></code>.</p>
|
||
</div>
|
||
<p>You can delete items in this mapping to unset environment variables.
|
||
<a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">unsetenv()</span></code></a> will be called automatically when an item is deleted from
|
||
<a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>, and when one of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">pop()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">clear()</span></code> methods is
|
||
called.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>Updated to support <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a>’s merge (<code class="docutils literal notranslate"><span class="pre">|</span></code>) and update (<code class="docutils literal notranslate"><span class="pre">|=</span></code>) operators.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.environb">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">environb</span></span><a class="headerlink" href="#os.environb" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Bytes version of <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">environ</span></code></a>: a <a class="reference internal" href="../glossary.html#term-mapping"><span class="xref std std-term">mapping</span></a> object where both keys
|
||
and values are <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> objects representing the process environment.
|
||
<a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">environ</span></code></a> and <a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">environb</span></code></a> are synchronized (modifying
|
||
<a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">environb</span></code></a> updates <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">environ</span></code></a>, and vice versa).</p>
|
||
<p><a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">environb</span></code></a> is only available if <a class="reference internal" href="#os.supports_bytes_environ" title="os.supports_bytes_environ"><code class="xref py py-const docutils literal notranslate"><span class="pre">supports_bytes_environ</span></code></a> is
|
||
<code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>Updated to support <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a>’s merge (<code class="docutils literal notranslate"><span class="pre">|</span></code>) and update (<code class="docutils literal notranslate"><span class="pre">|=</span></code>) operators.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span></dt>
|
||
<dt class="sig sig-object py">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fchdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span></dt>
|
||
<dt class="sig sig-object py">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getcwd</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
|
||
<dd><p>These functions are described in <a class="reference internal" href="#os-file-dir"><span class="std std-ref">Files and Directories</span></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fsencode">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fsencode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fsencode" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Encode <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like</span></a> <em>filename</em> to the
|
||
<a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>; return <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>
|
||
unchanged.</p>
|
||
<p><a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsdecode()</span></code></a> is the reverse function.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Support added to accept objects implementing the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>
|
||
interface.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fsdecode">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fsdecode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fsdecode" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Decode the <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like</span></a> <em>filename</em> from the
|
||
<a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>; return <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>
|
||
unchanged.</p>
|
||
<p><a class="reference internal" href="#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsencode()</span></code></a> is the reverse function.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Support added to accept objects implementing the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>
|
||
interface.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fspath">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fspath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fspath" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the file system representation of the path.</p>
|
||
<p>If <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> or <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> is passed in, it is returned unchanged.
|
||
Otherwise <a class="reference internal" href="#os.PathLike.__fspath__" title="os.PathLike.__fspath__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code></a> is called and its value is
|
||
returned as long as it is a <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> or <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> object.
|
||
In all other cases, <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="os.PathLike">
|
||
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PathLike</span></span><a class="headerlink" href="#os.PathLike" title="Link to this definition">¶</a></dt>
|
||
<dd><p>An <a class="reference internal" href="../glossary.html#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> for objects representing a file system path,
|
||
e.g. <a class="reference internal" href="pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.PurePath</span></code></a>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.PathLike.__fspath__">
|
||
<em class="property"><span class="k"><span class="pre">abstractmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">__fspath__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.PathLike.__fspath__" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the file system path representation of the object.</p>
|
||
<p>The method should only return a <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> or <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> object,
|
||
with the preference being for <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getenv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getenv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getenv" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the value of the environment variable <em>key</em> as a string if it exists, or
|
||
<em>default</em> if it doesn’t. <em>key</em> is a string. Note that
|
||
since <a class="reference internal" href="#os.getenv" title="os.getenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenv()</span></code></a> uses <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>, the mapping of <a class="reference internal" href="#os.getenv" title="os.getenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenv()</span></code></a> is
|
||
similarly also captured on import, and the function may not reflect
|
||
future environment changes.</p>
|
||
<p>On Unix, keys and values are decoded with <a class="reference internal" href="sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>
|
||
and <code class="docutils literal notranslate"><span class="pre">'surrogateescape'</span></code> error handler. Use <a class="reference internal" href="#os.getenvb" title="os.getenvb"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getenvb()</span></code></a> if you
|
||
would like to use a different encoding.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getenvb">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getenvb</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getenvb" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the value of the environment variable <em>key</em> as bytes if it exists, or
|
||
<em>default</em> if it doesn’t. <em>key</em> must be bytes. Note that
|
||
since <a class="reference internal" href="#os.getenvb" title="os.getenvb"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenvb()</span></code></a> uses <a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environb</span></code></a>, the mapping of <a class="reference internal" href="#os.getenvb" title="os.getenvb"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenvb()</span></code></a> is
|
||
similarly also captured on import, and the function may not reflect
|
||
future environment changes.</p>
|
||
<p><a class="reference internal" href="#os.getenvb" title="os.getenvb"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenvb()</span></code></a> is only available if <a class="reference internal" href="#os.supports_bytes_environ" title="os.supports_bytes_environ"><code class="xref py py-const docutils literal notranslate"><span class="pre">supports_bytes_environ</span></code></a>
|
||
is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.get_exec_path">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">get_exec_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">env</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.get_exec_path" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Returns the list of directories that will be searched for a named
|
||
executable, similar to a shell, when launching a process.
|
||
<em>env</em>, when specified, should be an environment variable dictionary
|
||
to lookup the PATH in.
|
||
By default, when <em>env</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">environ</span></code></a> is used.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getegid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getegid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getegid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the effective group id of the current process. This corresponds to the
|
||
“set id” bit on the file being executed in the current process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.geteuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">geteuid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.geteuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-8">Return the current process’s effective user id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getgid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-9">Return the real group id of the current process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
<p>The function is a stub on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getgrouplist">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getgrouplist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">user</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">group</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getgrouplist" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return list of group ids that <em>user</em> belongs to. If <em>group</em> is not in the
|
||
list, it is included; typically, <em>group</em> is specified as the group ID
|
||
field from the password record for <em>user</em>, because that group ID will
|
||
otherwise be potentially omitted.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getgroups">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getgroups</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getgroups" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return list of supplemental group ids associated with the current process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On macOS, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgroups()</span></code></a> behavior differs somewhat from
|
||
other Unix platforms. If the Python interpreter was built with a
|
||
deployment target of <code class="docutils literal notranslate"><span class="pre">10.5</span></code> or earlier, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgroups()</span></code></a> returns
|
||
the list of effective group ids associated with the current user process;
|
||
this list is limited to a system-defined number of entries, typically 16,
|
||
and may be modified by calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">setgroups()</span></code></a> if suitably privileged.
|
||
If built with a deployment target greater than <code class="docutils literal notranslate"><span class="pre">10.5</span></code>,
|
||
<a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgroups()</span></code></a> returns the current group access list for the user
|
||
associated with the effective user id of the process; the group access
|
||
list may change over the lifetime of the process, it is not affected by
|
||
calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">setgroups()</span></code></a>, and its length is not limited to 16. The
|
||
deployment target value, <code class="xref py py-const docutils literal notranslate"><span class="pre">MACOSX_DEPLOYMENT_TARGET</span></code>, can be
|
||
obtained with <a class="reference internal" href="sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_config_var()</span></code></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getlogin">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getlogin</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getlogin" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the name of the user logged in on the controlling terminal of the
|
||
process. For most purposes, it is more useful to use
|
||
<a class="reference internal" href="getpass.html#getpass.getuser" title="getpass.getuser"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpass.getuser()</span></code></a> since the latter checks the environment variables
|
||
<span class="target" id="index-10"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LOGNAME</span></code> or <span class="target" id="index-11"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERNAME</span></code> to find out who the user is, and
|
||
falls back to <code class="docutils literal notranslate"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></code> to get the login name of the
|
||
current real user id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getpgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getpgid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getpgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0,
|
||
the process group id of the current process is returned.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getpgrp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getpgrp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getpgrp" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-12">Return the id of the current process group.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getpid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getpid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getpid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-13">Return the current process id.</p>
|
||
<p>The function is a stub on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getppid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getppid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getppid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-14">Return the parent’s process id. When the parent process has exited, on Unix
|
||
the id returned is the one of the init process (1), on Windows it is still
|
||
the same id, which may be already reused by another process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added support for Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getpriority">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getpriority</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">who</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getpriority" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-15">Get program scheduling priority. The value <em>which</em> is one of
|
||
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PROCESS</span></code></a>, <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PGRP</span></code></a>, or <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_USER</span></code></a>, and <em>who</em>
|
||
is interpreted relative to <em>which</em> (a process identifier for
|
||
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PROCESS</span></code></a>, process group identifier for <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PGRP</span></code></a>, and a
|
||
user ID for <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_USER</span></code></a>). A zero value for <em>who</em> denotes
|
||
(respectively) the calling process, the process group of the calling process,
|
||
or the real user ID of the calling process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.PRIO_PROCESS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_PROCESS</span></span><a class="headerlink" href="#os.PRIO_PROCESS" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.PRIO_PGRP">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_PGRP</span></span><a class="headerlink" href="#os.PRIO_PGRP" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.PRIO_USER">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_USER</span></span><a class="headerlink" href="#os.PRIO_USER" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameters for the <a class="reference internal" href="#os.getpriority" title="os.getpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpriority()</span></code></a> and <a class="reference internal" href="#os.setpriority" title="os.setpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpriority()</span></code></a> functions.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.PRIO_DARWIN_THREAD">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_DARWIN_THREAD</span></span><a class="headerlink" href="#os.PRIO_DARWIN_THREAD" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.PRIO_DARWIN_PROCESS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_DARWIN_PROCESS</span></span><a class="headerlink" href="#os.PRIO_DARWIN_PROCESS" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.PRIO_DARWIN_BG">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_DARWIN_BG</span></span><a class="headerlink" href="#os.PRIO_DARWIN_BG" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.PRIO_DARWIN_NONUI">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PRIO_DARWIN_NONUI</span></span><a class="headerlink" href="#os.PRIO_DARWIN_NONUI" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameters for the <a class="reference internal" href="#os.getpriority" title="os.getpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpriority()</span></code></a> and <a class="reference internal" href="#os.setpriority" title="os.setpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpriority()</span></code></a> functions.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: macOS</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getresuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getresuid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getresuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a tuple (ruid, euid, suid) denoting the current process’s
|
||
real, effective, and saved user ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getresgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getresgid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getresgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a tuple (rgid, egid, sgid) denoting the current process’s
|
||
real, effective, and saved group ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getuid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-16">Return the current process’s real user id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
<p>The function is a stub on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.initgroups">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">initgroups</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">username</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.initgroups" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Call the system initgroups() to initialize the group access list with all of
|
||
the groups of which the specified username is a member, plus the specified
|
||
group id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.putenv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">putenv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.putenv" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-17">Set the environment variable named <em>key</em> to the string <em>value</em>. Such
|
||
changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.system()</span></code></a>,
|
||
<a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a> and <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal notranslate"><span class="pre">execv()</span></code></a>.</p>
|
||
<p>Assignments to items in <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> are automatically translated into
|
||
corresponding calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">putenv()</span></code></a>; however, calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">putenv()</span></code></a>
|
||
don’t update <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>, so it is actually preferable to assign to items
|
||
of <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>. This also applies to <a class="reference internal" href="#os.getenv" title="os.getenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenv()</span></code></a> and <a class="reference internal" href="#os.getenvb" title="os.getenvb"><code class="xref py py-func docutils literal notranslate"><span class="pre">getenvb()</span></code></a>, which
|
||
respectively use <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> and <a class="reference internal" href="#os.environb" title="os.environb"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environb</span></code></a> in their implementations.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On some platforms, including FreeBSD and macOS, setting <code class="docutils literal notranslate"><span class="pre">environ</span></code> may
|
||
cause memory leaks. Refer to the system documentation for <code class="xref c c-func docutils literal notranslate"><span class="pre">putenv()</span></code>.</p>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.putenv</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>The function is now always available.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setegid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setegid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">egid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setegid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s effective group id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.seteuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">seteuid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">euid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.seteuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s effective user id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setgid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’ group id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setgroups">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setgroups</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">groups</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setgroups" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the list of supplemental group ids associated with the current process to
|
||
<em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer
|
||
identifying a group. This operation is typically available only to the superuser.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On macOS, the length of <em>groups</em> may not exceed the
|
||
system-defined maximum number of effective group ids, typically 16.
|
||
See the documentation for <a class="reference internal" href="#os.getgroups" title="os.getgroups"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgroups()</span></code></a> for cases where it may not
|
||
return the same group list set by calling setgroups().</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setns">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setns</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nstype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Reassociate the current thread with a Linux namespace.
|
||
See the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/setns(2)">setns(2)</a></em> and <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/namespaces(7)">namespaces(7)</a></em> man pages for more
|
||
details.</p>
|
||
<p>If <em>fd</em> refers to a <code class="file docutils literal notranslate"><span class="pre">/proc/</span><em><span class="pre">pid</span></em><span class="pre">/ns/</span></code> link, <code class="docutils literal notranslate"><span class="pre">setns()</span></code> reassociates the
|
||
calling thread with the namespace associated with that link,
|
||
and <em>nstype</em> may be set to one of the
|
||
<a class="reference internal" href="#os-unshare-clone-flags"><span class="std std-ref">CLONE_NEW* constants</span></a>
|
||
to impose constraints on the operation
|
||
(<code class="docutils literal notranslate"><span class="pre">0</span></code> means no constraints).</p>
|
||
<p>Since Linux 5.8, <em>fd</em> may refer to a PID file descriptor obtained from
|
||
<a class="reference internal" href="#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">pidfd_open()</span></code></a>. In this case, <code class="docutils literal notranslate"><span class="pre">setns()</span></code> reassociates the calling thread
|
||
into one or more of the same namespaces as the thread referred to by <em>fd</em>.
|
||
This is subject to any constraints imposed by <em>nstype</em>,
|
||
which is a bit mask combining one or more of the
|
||
<a class="reference internal" href="#os-unshare-clone-flags"><span class="std std-ref">CLONE_NEW* constants</span></a>,
|
||
e.g. <code class="docutils literal notranslate"><span class="pre">setns(fd,</span> <span class="pre">os.CLONE_NEWUTS</span> <span class="pre">|</span> <span class="pre">os.CLONE_NEWPID)</span></code>.
|
||
The caller’s memberships in unspecified namespaces are left unchanged.</p>
|
||
<p><em>fd</em> can be any object with a <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method, or a raw file descriptor.</p>
|
||
<p>This example reassociates the thread with the <code class="docutils literal notranslate"><span class="pre">init</span></code> process’s network namespace:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">fd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"/proc/1/ns/net"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">O_RDONLY</span><span class="p">)</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">setns</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">CLONE_NEWNET</span><span class="p">)</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 3.0 with glibc >= 2.14.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="#os.unshare" title="os.unshare"><code class="xref py py-func docutils literal notranslate"><span class="pre">unshare()</span></code></a> function.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setpgrp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setpgrp</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.setpgrp" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Call the system call <code class="xref c c-func docutils literal notranslate"><span class="pre">setpgrp()</span></code> or <code class="docutils literal notranslate"><span class="pre">setpgrp(0,</span> <span class="pre">0)</span></code> depending on
|
||
which version is implemented (if any). See the Unix manual for the semantics.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setpgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setpgid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pgrp</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setpgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Call the system call <code class="xref c c-func docutils literal notranslate"><span class="pre">setpgid()</span></code> to set the process group id of the
|
||
process with id <em>pid</em> to the process group with id <em>pgrp</em>. See the Unix manual
|
||
for the semantics.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setpriority">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setpriority</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">who</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">priority</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setpriority" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-18">Set program scheduling priority. The value <em>which</em> is one of
|
||
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PROCESS</span></code></a>, <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PGRP</span></code></a>, or <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_USER</span></code></a>, and <em>who</em>
|
||
is interpreted relative to <em>which</em> (a process identifier for
|
||
<a class="reference internal" href="#os.PRIO_PROCESS" title="os.PRIO_PROCESS"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PROCESS</span></code></a>, process group identifier for <a class="reference internal" href="#os.PRIO_PGRP" title="os.PRIO_PGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_PGRP</span></code></a>, and a
|
||
user ID for <a class="reference internal" href="#os.PRIO_USER" title="os.PRIO_USER"><code class="xref py py-const docutils literal notranslate"><span class="pre">PRIO_USER</span></code></a>). A zero value for <em>who</em> denotes
|
||
(respectively) the calling process, the process group of the calling process,
|
||
or the real user ID of the calling process.
|
||
<em>priority</em> is a value in the range -20 to 19. The default priority is 0;
|
||
lower priorities cause more favorable scheduling.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setregid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setregid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rgid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">egid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setregid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s real and effective group ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setresgid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setresgid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rgid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">egid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sgid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setresgid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s real, effective, and saved group ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setresuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setresuid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ruid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">euid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">suid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setresuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s real, effective, and saved user ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setreuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setreuid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ruid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">euid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setreuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current process’s real and effective user ids.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getsid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getsid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getsid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Call the system call <code class="xref c c-func docutils literal notranslate"><span class="pre">getsid()</span></code>. See the Unix manual for the semantics.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setsid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setsid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.setsid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Call the system call <code class="xref c c-func docutils literal notranslate"><span class="pre">setsid()</span></code>. See the Unix manual for the semantics.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setuid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setuid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">uid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setuid" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-19">Set the current process’s user id.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.strerror">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">strerror</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.strerror" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the error message corresponding to the error code in <em>code</em>.
|
||
On platforms where <code class="xref c c-func docutils literal notranslate"><span class="pre">strerror()</span></code> returns <code class="docutils literal notranslate"><span class="pre">NULL</span></code> when given an unknown
|
||
error number, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.supports_bytes_environ">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">supports_bytes_environ</span></span><a class="headerlink" href="#os.supports_bytes_environ" title="Link to this definition">¶</a></dt>
|
||
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the native OS type of the environment is bytes (eg. <code class="docutils literal notranslate"><span class="pre">False</span></code> on
|
||
Windows).</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.2.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.umask">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">umask</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mask</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.umask" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current numeric umask and return the previous umask.</p>
|
||
<p>The function is a stub on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.uname">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">uname</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.uname" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-20">Returns information identifying the current operating system.
|
||
The return value is an object with five attributes:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">sysname</span></code> - operating system name</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">nodename</span></code> - name of machine on network (implementation-defined)</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">release</span></code> - operating system release</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">version</span></code> - operating system version</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">machine</span></code> - hardware identifier</p></li>
|
||
</ul>
|
||
<p>For backwards compatibility, this object is also iterable, behaving
|
||
like a five-tuple containing <code class="xref py py-attr docutils literal notranslate"><span class="pre">sysname</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodename</span></code>,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">release</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">version</span></code>, and <code class="xref py py-attr docutils literal notranslate"><span class="pre">machine</span></code>
|
||
in that order.</p>
|
||
<p>Some systems truncate <code class="xref py py-attr docutils literal notranslate"><span class="pre">nodename</span></code> to 8 characters or to the
|
||
leading component; a better way to get the hostname is
|
||
<a class="reference internal" href="socket.html#socket.gethostname" title="socket.gethostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.gethostname()</span></code></a> or even
|
||
<code class="docutils literal notranslate"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></code>.</p>
|
||
<p>On macOS, iOS and Android, this returns the <em>kernel</em> name and version (i.e.,
|
||
<code class="docutils literal notranslate"><span class="pre">'Darwin'</span></code> on macOS and iOS; <code class="docutils literal notranslate"><span class="pre">'Linux'</span></code> on Android). <a class="reference internal" href="platform.html#platform.uname" title="platform.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.uname()</span></code></a>
|
||
can be used to get the user-facing operating system name and version on iOS and
|
||
Android.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Return type changed from a tuple to a tuple-like object
|
||
with named attributes.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.unsetenv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">unsetenv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.unsetenv" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-21">Unset (delete) the environment variable named <em>key</em>. Such changes to the
|
||
environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.system()</span></code></a>, <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or
|
||
<a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a> and <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal notranslate"><span class="pre">execv()</span></code></a>.</p>
|
||
<p>Deletion of items in <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a> is automatically translated into a
|
||
corresponding call to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">unsetenv()</span></code></a>; however, calls to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">unsetenv()</span></code></a>
|
||
don’t update <a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>, so it is actually preferable to delete items of
|
||
<a class="reference internal" href="#os.environ" title="os.environ"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.environ</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.unsetenv</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>The function is now always available and is also available on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.unshare">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">unshare</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">flags</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.unshare" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Disassociate parts of the process execution context, and move them into a
|
||
newly created namespace.
|
||
See the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/unshare(2)">unshare(2)</a></em>
|
||
man page for more details.
|
||
The <em>flags</em> argument is a bit mask, combining zero or more of the
|
||
<a class="reference internal" href="#os-unshare-clone-flags"><span class="std std-ref">CLONE_* constants</span></a>,
|
||
that specifies which parts of the execution context should be
|
||
unshared from their existing associations and moved to a new namespace.
|
||
If the <em>flags</em> argument is <code class="docutils literal notranslate"><span class="pre">0</span></code>, no changes are made to the calling process’s
|
||
execution context.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.16.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="#os.setns" title="os.setns"><code class="xref py py-func docutils literal notranslate"><span class="pre">setns()</span></code></a> function.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p id="os-unshare-clone-flags">Flags to the <a class="reference internal" href="#os.unshare" title="os.unshare"><code class="xref py py-func docutils literal notranslate"><span class="pre">unshare()</span></code></a> function, if the implementation supports them.
|
||
See <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/unshare(2)">unshare(2)</a></em> in the Linux manual
|
||
for their exact effect and availability.</p>
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.CLONE_FILES">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_FILES</span></span><a class="headerlink" href="#os.CLONE_FILES" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_FS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_FS</span></span><a class="headerlink" href="#os.CLONE_FS" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWCGROUP">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWCGROUP</span></span><a class="headerlink" href="#os.CLONE_NEWCGROUP" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWIPC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWIPC</span></span><a class="headerlink" href="#os.CLONE_NEWIPC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWNET">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWNET</span></span><a class="headerlink" href="#os.CLONE_NEWNET" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWNS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWNS</span></span><a class="headerlink" href="#os.CLONE_NEWNS" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWPID">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWPID</span></span><a class="headerlink" href="#os.CLONE_NEWPID" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWTIME">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWTIME</span></span><a class="headerlink" href="#os.CLONE_NEWTIME" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWUSER">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWUSER</span></span><a class="headerlink" href="#os.CLONE_NEWUSER" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_NEWUTS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_NEWUTS</span></span><a class="headerlink" href="#os.CLONE_NEWUTS" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_SIGHAND">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_SIGHAND</span></span><a class="headerlink" href="#os.CLONE_SIGHAND" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_SYSVSEM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_SYSVSEM</span></span><a class="headerlink" href="#os.CLONE_SYSVSEM" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_THREAD">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_THREAD</span></span><a class="headerlink" href="#os.CLONE_THREAD" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLONE_VM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLONE_VM</span></span><a class="headerlink" href="#os.CLONE_VM" title="Link to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</section>
|
||
<section id="file-object-creation">
|
||
<span id="os-newstreams"></span><h2>File Object Creation<a class="headerlink" href="#file-object-creation" title="Link to this heading">¶</a></h2>
|
||
<p>These functions create new <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file objects</span></a>. (See also
|
||
<a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> for opening file descriptors.)</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fdopen">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fdopen</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fdopen" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return an open file object connected to the file descriptor <em>fd</em>. This is an
|
||
alias of the <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> built-in function and accepts the same arguments.
|
||
The only difference is that the first argument of <a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdopen()</span></code></a> must always
|
||
be an integer.</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="file-descriptor-operations">
|
||
<span id="os-fd-ops"></span><h2>File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Link to this heading">¶</a></h2>
|
||
<p>These functions operate on I/O streams referenced using file descriptors.</p>
|
||
<p>File descriptors are small integers corresponding to a file that has been opened
|
||
by the current process. For example, standard input is usually file descriptor
|
||
0, standard output is 1, and standard error is 2. Further files opened by a
|
||
process will then be assigned 3, 4, 5, and so forth. The name “file descriptor”
|
||
is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
|
||
by file descriptors.</p>
|
||
<p>The <a class="reference internal" href="io.html#io.IOBase.fileno" title="io.IOBase.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> method can be used to obtain the file descriptor
|
||
associated with a <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file object</span></a> when required. Note that using the file
|
||
descriptor directly will bypass the file object methods, ignoring aspects such
|
||
as internal buffering of data.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.close">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.close" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Close file descriptor <em>fd</em>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function is intended for low-level I/O and must be applied to a file
|
||
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal notranslate"><span class="pre">pipe()</span></code></a>. To close a “file
|
||
object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or
|
||
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdopen()</span></code></a>, use its <a class="reference internal" href="io.html#io.IOBase.close" title="io.IOBase.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.closerange">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">closerange</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd_low</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fd_high</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.closerange" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive),
|
||
ignoring errors. Equivalent to (but much faster than):</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">fd_low</span><span class="p">,</span> <span class="n">fd_high</span><span class="p">):</span>
|
||
<span class="k">try</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
|
||
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
|
||
<span class="k">pass</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.copy_file_range">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">copy_file_range</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset_src</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset_dst</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.copy_file_range" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Copy <em>count</em> bytes from file descriptor <em>src</em>, starting from offset
|
||
<em>offset_src</em>, to file descriptor <em>dst</em>, starting from offset <em>offset_dst</em>.
|
||
If <em>offset_src</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, then <em>src</em> is read from the current position;
|
||
respectively for <em>offset_dst</em>.</p>
|
||
<p>In Linux kernel older than 5.3, the files pointed to by <em>src</em> and <em>dst</em>
|
||
must reside in the same filesystem, otherwise an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is
|
||
raised with <a class="reference internal" href="exceptions.html#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> set to <a class="reference internal" href="errno.html#errno.EXDEV" title="errno.EXDEV"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EXDEV</span></code></a>.</p>
|
||
<p>This copy is done without the additional cost of transferring data
|
||
from the kernel to user space and then back into the kernel. Additionally,
|
||
some filesystems could implement extra optimizations, such as the use of
|
||
reflinks (i.e., two or more inodes that share pointers to the same
|
||
copy-on-write disk blocks; supported file systems include btrfs and XFS)
|
||
and server-side copy (in the case of NFS).</p>
|
||
<p>The function copies bytes between two file descriptors. Text options, like
|
||
the encoding and the line ending, are ignored.</p>
|
||
<p>The return value is the amount of bytes copied. This could be less than the
|
||
amount requested.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On Linux, <a class="reference internal" href="#os.copy_file_range" title="os.copy_file_range"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.copy_file_range()</span></code></a> should not be used for copying a
|
||
range of a pseudo file from a special filesystem like procfs and sysfs.
|
||
It will always copy no bytes and return 0 as if the file was empty
|
||
because of a known Linux kernel issue.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.5 with glibc >= 2.27.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.device_encoding">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">device_encoding</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.device_encoding" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a string describing the encoding of the device associated with <em>fd</em>
|
||
if it is connected to a terminal; else return <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>.</p>
|
||
<p>On Unix, if the <a class="reference internal" href="#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is enabled, return
|
||
<code class="docutils literal notranslate"><span class="pre">'UTF-8'</span></code> rather than the device encoding.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.10: </span>On Unix, the function now implements the Python UTF-8 Mode.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.dup">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">dup</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.dup" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a duplicate of file descriptor <em>fd</em>. The new file descriptor is
|
||
<a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
|
||
<p>On Windows, when duplicating a standard stream (0: stdin, 1: stdout,
|
||
2: stderr), the new file descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">inheritable</span></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.dup2">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">dup2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fd2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inheritable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.dup2" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if
|
||
necessary. Return <em>fd2</em>. The new file descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">inheritable</span></a> by default or non-inheritable if <em>inheritable</em>
|
||
is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>Add the optional <em>inheritable</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>Return <em>fd2</em> on success. Previously, <code class="docutils literal notranslate"><span class="pre">None</span></code> was always returned.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fchmod">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fchmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchmod" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>. See the
|
||
docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a> for possible values of <em>mode</em>. As of Python 3.3, this
|
||
is equivalent to <code class="docutils literal notranslate"><span class="pre">os.chmod(fd,</span> <span class="pre">mode)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chmod</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>Added support on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fchown">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fchown</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gid</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchown" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em>
|
||
and <em>gid</em>. To leave one of the ids unchanged, set it to -1. See
|
||
<a class="reference internal" href="#os.chown" title="os.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>. As of Python 3.3, this is equivalent to <code class="docutils literal notranslate"><span class="pre">os.chown(fd,</span> <span class="pre">uid,</span>
|
||
<span class="pre">gid)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chown</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">uid</span></code>, <code class="docutils literal notranslate"><span class="pre">gid</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fdatasync">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fdatasync</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fdatasync" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of
|
||
metadata.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function is not available on MacOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fpathconf">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fpathconf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fpathconf" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return system configuration information relevant to an open file. <em>name</em>
|
||
specifies the configuration value to retrieve; it may be a string which is the
|
||
name of a defined system value; these names are specified in a number of
|
||
standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define
|
||
additional names as well. The names known to the host operating system are
|
||
given in the <code class="docutils literal notranslate"><span class="pre">pathconf_names</span></code> dictionary. For configuration variables not
|
||
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
|
||
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. If a
|
||
specific value for <em>name</em> is not supported by the host system, even if it is
|
||
included in <code class="docutils literal notranslate"><span class="pre">pathconf_names</span></code>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised with
|
||
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
|
||
<p>As of Python 3.3, this is equivalent to <code class="docutils literal notranslate"><span class="pre">os.pathconf(fd,</span> <span class="pre">name)</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fstat">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fstat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fstat" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the status of the file descriptor <em>fd</em>. Return a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a>
|
||
object.</p>
|
||
<p>As of Python 3.3, this is equivalent to <code class="docutils literal notranslate"><span class="pre">os.stat(fd)</span></code>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a> function.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fstatvfs">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fstatvfs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fstatvfs" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return information about the filesystem containing the file associated with
|
||
file descriptor <em>fd</em>, like <a class="reference internal" href="#os.statvfs" title="os.statvfs"><code class="xref py py-func docutils literal notranslate"><span class="pre">statvfs()</span></code></a>. As of Python 3.3, this is
|
||
equivalent to <code class="docutils literal notranslate"><span class="pre">os.statvfs(fd)</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fsync">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fsync</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fsync" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk. On Unix, this calls the
|
||
native <code class="xref c c-func docutils literal notranslate"><span class="pre">fsync()</span></code> function; on Windows, the MS <code class="xref c c-func docutils literal notranslate"><span class="pre">_commit()</span></code> function.</p>
|
||
<p>If you’re starting with a buffered Python <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file object</span></a> <em>f</em>, first do
|
||
<code class="docutils literal notranslate"><span class="pre">f.flush()</span></code>, and then do <code class="docutils literal notranslate"><span class="pre">os.fsync(f.fileno())</span></code>, to ensure that all internal
|
||
buffers associated with <em>f</em> are written to disk.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.ftruncate">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">ftruncate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.ftruncate" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at
|
||
most <em>length</em> bytes in size. As of Python 3.3, this is equivalent to
|
||
<code class="docutils literal notranslate"><span class="pre">os.truncate(fd,</span> <span class="pre">length)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.truncate</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">fd</span></code>, <code class="docutils literal notranslate"><span class="pre">length</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>Added support for Windows</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.get_blocking">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">get_blocking</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.get_blocking" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the blocking mode of the file descriptor: <code class="docutils literal notranslate"><span class="pre">False</span></code> if the
|
||
<a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> flag is set, <code class="docutils literal notranslate"><span class="pre">True</span></code> if the flag is cleared.</p>
|
||
<p>See also <a class="reference internal" href="#os.set_blocking" title="os.set_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_blocking()</span></code></a> and <a class="reference internal" href="socket.html#socket.socket.setblocking" title="socket.socket.setblocking"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.setblocking()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
<p>On Windows, this function is limited to pipes.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.5.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>Added support for pipes on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.grantpt">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">grantpt</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.grantpt" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Grant access to the slave pseudo-terminal device associated with the
|
||
master pseudo-terminal device to which the file descriptor <em>fd</em> refers.
|
||
The file descriptor <em>fd</em> is not closed upon failure.</p>
|
||
<p>Calls the C standard library function <code class="xref c c-func docutils literal notranslate"><span class="pre">grantpt()</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.isatty">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">isatty</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.isatty" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the file descriptor <em>fd</em> is open and connected to a
|
||
tty(-like) device, else <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lockf">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lockf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">len</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lockf" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Apply, test or remove a POSIX lock on an open file descriptor.
|
||
<em>fd</em> is an open file descriptor.
|
||
<em>cmd</em> specifies the command to use - one of <a class="reference internal" href="#os.F_LOCK" title="os.F_LOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">F_LOCK</span></code></a>, <a class="reference internal" href="#os.F_TLOCK" title="os.F_TLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">F_TLOCK</span></code></a>,
|
||
<a class="reference internal" href="#os.F_ULOCK" title="os.F_ULOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">F_ULOCK</span></code></a> or <a class="reference internal" href="#os.F_TEST" title="os.F_TEST"><code class="xref py py-data docutils literal notranslate"><span class="pre">F_TEST</span></code></a>.
|
||
<em>len</em> specifies the section of the file to lock.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.lockf</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">fd</span></code>, <code class="docutils literal notranslate"><span class="pre">cmd</span></code>, <code class="docutils literal notranslate"><span class="pre">len</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.F_LOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">F_LOCK</span></span><a class="headerlink" href="#os.F_LOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.F_TLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">F_TLOCK</span></span><a class="headerlink" href="#os.F_TLOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.F_ULOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">F_ULOCK</span></span><a class="headerlink" href="#os.F_ULOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.F_TEST">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">F_TEST</span></span><a class="headerlink" href="#os.F_TEST" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Flags that specify what action <a class="reference internal" href="#os.lockf" title="os.lockf"><code class="xref py py-func docutils literal notranslate"><span class="pre">lockf()</span></code></a> will take.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.login_tty">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">login_tty</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.login_tty" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Prepare the tty of which fd is a file descriptor for a new login session.
|
||
Make the calling process a session leader; make the tty the controlling tty,
|
||
the stdin, the stdout, and the stderr of the calling process; close fd.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.11.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lseek">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lseek</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pos</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">whence</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lseek" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified
|
||
by <em>whence</em>, and return the new position in bytes relative to
|
||
the start of the file.
|
||
Valid values for <em>whence</em> are:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_SET</span></code></a> or <code class="docutils literal notranslate"><span class="pre">0</span></code> – set <em>pos</em> relative to the beginning of the file</p></li>
|
||
<li><p><a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_CUR</span></code></a> or <code class="docutils literal notranslate"><span class="pre">1</span></code> – set <em>pos</em> relative to the current file position</p></li>
|
||
<li><p><a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_END</span></code></a> or <code class="docutils literal notranslate"><span class="pre">2</span></code> – set <em>pos</em> relative to the end of the file</p></li>
|
||
<li><p><a class="reference internal" href="#os.SEEK_HOLE" title="os.SEEK_HOLE"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_HOLE</span></code></a> – set <em>pos</em> to the next data location, relative to <em>pos</em></p></li>
|
||
<li><p><a class="reference internal" href="#os.SEEK_DATA" title="os.SEEK_DATA"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_DATA</span></code></a> – set <em>pos</em> to the next data hole, relative to <em>pos</em></p></li>
|
||
</ul>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Add support for <code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_HOLE</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_DATA</span></code>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SEEK_SET">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SEEK_SET</span></span><a class="headerlink" href="#os.SEEK_SET" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SEEK_CUR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SEEK_CUR</span></span><a class="headerlink" href="#os.SEEK_CUR" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SEEK_END">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SEEK_END</span></span><a class="headerlink" href="#os.SEEK_END" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><code class="xref py py-func docutils literal notranslate"><span class="pre">lseek()</span></code></a> function and the <a class="reference internal" href="io.html#io.IOBase.seek" title="io.IOBase.seek"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code></a>
|
||
method on <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file-like objects</span></a>,
|
||
for whence to adjust the file position indicator.</p>
|
||
<dl class="simple">
|
||
<dt><a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_SET</span></code></a></dt><dd><p>Adjust the file position relative to the beginning of the file.</p>
|
||
</dd>
|
||
<dt><a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_CUR</span></code></a></dt><dd><p>Adjust the file position relative to the current file position.</p>
|
||
</dd>
|
||
<dt><a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_END</span></code></a></dt><dd><p>Adjust the file position relative to the end of the file.</p>
|
||
</dd>
|
||
</dl>
|
||
<p>Their values are 0, 1, and 2, respectively.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SEEK_HOLE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SEEK_HOLE</span></span><a class="headerlink" href="#os.SEEK_HOLE" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SEEK_DATA">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SEEK_DATA</span></span><a class="headerlink" href="#os.SEEK_DATA" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><code class="xref py py-func docutils literal notranslate"><span class="pre">lseek()</span></code></a> function and the <a class="reference internal" href="io.html#io.IOBase.seek" title="io.IOBase.seek"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code></a>
|
||
method on <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file-like objects</span></a>,
|
||
for seeking file data and holes on sparsely allocated files.</p>
|
||
<dl class="simple">
|
||
<dt><code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_DATA</span></code></dt><dd><p>Adjust the file offset to the next location containing data,
|
||
relative to the seek position.</p>
|
||
</dd>
|
||
<dt><code class="xref py py-data docutils literal notranslate"><span class="pre">SEEK_HOLE</span></code></dt><dd><p>Adjust the file offset to the next location containing a hole,
|
||
relative to the seek position.
|
||
A hole is defined as a sequence of zeros.</p>
|
||
</dd>
|
||
</dl>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>These operations only make sense for filesystems that support them.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 3.1, macOS, Unix</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.open">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o777</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.open" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Open the file <em>path</em> and set various flags according to <em>flags</em> and possibly
|
||
its mode according to <em>mode</em>. When computing <em>mode</em>, the current umask value
|
||
is first masked out. Return the file descriptor for the newly opened file.
|
||
The new file descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
|
||
<p>For a description of the flag and mode values, see the C run-time documentation;
|
||
flag constants (like <a class="reference internal" href="#os.O_RDONLY" title="os.O_RDONLY"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_RDONLY</span></code></a> and <a class="reference internal" href="#os.O_WRONLY" title="os.O_WRONLY"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_WRONLY</span></code></a>) are defined in
|
||
the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module. In particular, on Windows adding
|
||
<a class="reference internal" href="#os.O_BINARY" title="os.O_BINARY"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_BINARY</span></code></a> is needed to open files in binary mode.</p>
|
||
<p>This function can support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a> with the <em>dir_fd</em> parameter.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">open</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">flags</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptor is now non-inheritable.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function is intended for low-level I/O. For normal usage, use the
|
||
built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, which returns a <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file object</span></a> with
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> methods (and many more). To
|
||
wrap a file descriptor in a file object, use <a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdopen()</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>If the system call is interrupted and the signal handler does not raise an
|
||
exception, the function now retries the system call instead of raising an
|
||
<a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> exception (see <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale).</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>The following constants are options for the <em>flags</em> parameter to the
|
||
<a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function. They can be combined using the bitwise OR operator
|
||
<code class="docutils literal notranslate"><span class="pre">|</span></code>. Some of them are not available on all platforms. For descriptions of
|
||
their availability and use, consult the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/open(2)">open(2)</a></em> manual page on Unix
|
||
or <a class="reference external" href="https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx">the MSDN</a> on Windows.</p>
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.O_RDONLY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_RDONLY</span></span><a class="headerlink" href="#os.O_RDONLY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_WRONLY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_WRONLY</span></span><a class="headerlink" href="#os.O_WRONLY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_RDWR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_RDWR</span></span><a class="headerlink" href="#os.O_RDWR" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_APPEND">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_APPEND</span></span><a class="headerlink" href="#os.O_APPEND" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_CREAT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_CREAT</span></span><a class="headerlink" href="#os.O_CREAT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_EXCL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_EXCL</span></span><a class="headerlink" href="#os.O_EXCL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_TRUNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_TRUNC</span></span><a class="headerlink" href="#os.O_TRUNC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The above constants are available on Unix and Windows.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.O_DSYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_DSYNC</span></span><a class="headerlink" href="#os.O_DSYNC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_RSYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_RSYNC</span></span><a class="headerlink" href="#os.O_RSYNC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_SYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_SYNC</span></span><a class="headerlink" href="#os.O_SYNC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NDELAY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NDELAY</span></span><a class="headerlink" href="#os.O_NDELAY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NONBLOCK</span></span><a class="headerlink" href="#os.O_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NOCTTY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NOCTTY</span></span><a class="headerlink" href="#os.O_NOCTTY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_CLOEXEC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_CLOEXEC</span></span><a class="headerlink" href="#os.O_CLOEXEC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The above constants are only available on Unix.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Add <a class="reference internal" href="#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_CLOEXEC</span></code></a> constant.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.O_BINARY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_BINARY</span></span><a class="headerlink" href="#os.O_BINARY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NOINHERIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NOINHERIT</span></span><a class="headerlink" href="#os.O_NOINHERIT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_SHORT_LIVED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_SHORT_LIVED</span></span><a class="headerlink" href="#os.O_SHORT_LIVED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_TEMPORARY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_TEMPORARY</span></span><a class="headerlink" href="#os.O_TEMPORARY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_RANDOM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_RANDOM</span></span><a class="headerlink" href="#os.O_RANDOM" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_SEQUENTIAL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_SEQUENTIAL</span></span><a class="headerlink" href="#os.O_SEQUENTIAL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_TEXT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_TEXT</span></span><a class="headerlink" href="#os.O_TEXT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The above constants are only available on Windows.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.O_EVTONLY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_EVTONLY</span></span><a class="headerlink" href="#os.O_EVTONLY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_FSYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_FSYNC</span></span><a class="headerlink" href="#os.O_FSYNC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_SYMLINK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_SYMLINK</span></span><a class="headerlink" href="#os.O_SYMLINK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NOFOLLOW_ANY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NOFOLLOW_ANY</span></span><a class="headerlink" href="#os.O_NOFOLLOW_ANY" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The above constants are only available on macOS.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.10: </span>Add <a class="reference internal" href="#os.O_EVTONLY" title="os.O_EVTONLY"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_EVTONLY</span></code></a>, <a class="reference internal" href="#os.O_FSYNC" title="os.O_FSYNC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_FSYNC</span></code></a>, <a class="reference internal" href="#os.O_SYMLINK" title="os.O_SYMLINK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_SYMLINK</span></code></a>
|
||
and <a class="reference internal" href="#os.O_NOFOLLOW_ANY" title="os.O_NOFOLLOW_ANY"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NOFOLLOW_ANY</span></code></a> constants.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.O_ASYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_ASYNC</span></span><a class="headerlink" href="#os.O_ASYNC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_DIRECT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_DIRECT</span></span><a class="headerlink" href="#os.O_DIRECT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_DIRECTORY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_DIRECTORY</span></span><a class="headerlink" href="#os.O_DIRECTORY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NOFOLLOW">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NOFOLLOW</span></span><a class="headerlink" href="#os.O_NOFOLLOW" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_NOATIME">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_NOATIME</span></span><a class="headerlink" href="#os.O_NOATIME" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_PATH">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_PATH</span></span><a class="headerlink" href="#os.O_PATH" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_TMPFILE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_TMPFILE</span></span><a class="headerlink" href="#os.O_TMPFILE" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_SHLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_SHLOCK</span></span><a class="headerlink" href="#os.O_SHLOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.O_EXLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">O_EXLOCK</span></span><a class="headerlink" href="#os.O_EXLOCK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The above constants are extensions and not present if they are not defined by
|
||
the C library.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>Add <a class="reference internal" href="#os.O_PATH" title="os.O_PATH"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_PATH</span></code></a> on systems that support it.
|
||
Add <a class="reference internal" href="#os.O_TMPFILE" title="os.O_TMPFILE"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_TMPFILE</span></code></a>, only available on Linux Kernel 3.11
|
||
or newer.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.openpty">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">openpty</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.openpty" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-23">Open a new pseudo-terminal pair. Return a pair of file descriptors
|
||
<code class="docutils literal notranslate"><span class="pre">(master,</span> <span class="pre">slave)</span></code> for the pty and the tty, respectively. The new file
|
||
descriptors are <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>. For a (slightly) more
|
||
portable approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Unix. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code></a> module.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptors are now non-inheritable.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pipe">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pipe</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.pipe" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a pipe. Return a pair of file descriptors <code class="docutils literal notranslate"><span class="pre">(r,</span> <span class="pre">w)</span></code> usable for
|
||
reading and writing, respectively. The new file descriptor is
|
||
<a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>The new file descriptors are now non-inheritable.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pipe2">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pipe2</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">flags</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pipe2" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a pipe with <em>flags</em> set atomically.
|
||
<em>flags</em> can be constructed by ORing together one or more of these values:
|
||
<a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a>, <a class="reference internal" href="#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_CLOEXEC</span></code></a>.
|
||
Return a pair of file descriptors <code class="docutils literal notranslate"><span class="pre">(r,</span> <span class="pre">w)</span></code> usable for reading and writing,
|
||
respectively.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.posix_fallocate">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">posix_fallocate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">len</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.posix_fallocate" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Ensures that enough disk space is allocated for the file specified by <em>fd</em>
|
||
starting from <em>offset</em> and continuing for <em>len</em> bytes.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.posix_fadvise">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">posix_fadvise</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">len</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">advice</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.posix_fadvise" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Announces an intention to access data in a specific pattern thus allowing
|
||
the kernel to make optimizations.
|
||
The advice applies to the region of the file specified by <em>fd</em> starting at
|
||
<em>offset</em> and continuing for <em>len</em> bytes.
|
||
<em>advice</em> is one of <a class="reference internal" href="#os.POSIX_FADV_NORMAL" title="os.POSIX_FADV_NORMAL"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_NORMAL</span></code></a>, <a class="reference internal" href="#os.POSIX_FADV_SEQUENTIAL" title="os.POSIX_FADV_SEQUENTIAL"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_SEQUENTIAL</span></code></a>,
|
||
<a class="reference internal" href="#os.POSIX_FADV_RANDOM" title="os.POSIX_FADV_RANDOM"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_RANDOM</span></code></a>, <a class="reference internal" href="#os.POSIX_FADV_NOREUSE" title="os.POSIX_FADV_NOREUSE"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_NOREUSE</span></code></a>,
|
||
<a class="reference internal" href="#os.POSIX_FADV_WILLNEED" title="os.POSIX_FADV_WILLNEED"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_WILLNEED</span></code></a> or <a class="reference internal" href="#os.POSIX_FADV_DONTNEED" title="os.POSIX_FADV_DONTNEED"><code class="xref py py-data docutils literal notranslate"><span class="pre">POSIX_FADV_DONTNEED</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_NORMAL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_NORMAL</span></span><a class="headerlink" href="#os.POSIX_FADV_NORMAL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_SEQUENTIAL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_SEQUENTIAL</span></span><a class="headerlink" href="#os.POSIX_FADV_SEQUENTIAL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_RANDOM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_RANDOM</span></span><a class="headerlink" href="#os.POSIX_FADV_RANDOM" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_NOREUSE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_NOREUSE</span></span><a class="headerlink" href="#os.POSIX_FADV_NOREUSE" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_WILLNEED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_WILLNEED</span></span><a class="headerlink" href="#os.POSIX_FADV_WILLNEED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.POSIX_FADV_DONTNEED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_FADV_DONTNEED</span></span><a class="headerlink" href="#os.POSIX_FADV_DONTNEED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Flags that can be used in <em>advice</em> in <a class="reference internal" href="#os.posix_fadvise" title="os.posix_fadvise"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fadvise()</span></code></a> that specify
|
||
the access pattern that is likely to be used.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pread">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pread</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pread" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em> at a position of <em>offset</em>,
|
||
leaving the file offset unchanged.</p>
|
||
<p>Return a bytestring containing the bytes read. If the end of the file
|
||
referred to by <em>fd</em> has been reached, an empty bytes object is returned.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.posix_openpt">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">posix_openpt</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">oflag</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.posix_openpt" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Open and return a file descriptor for a master pseudo-terminal device.</p>
|
||
<p>Calls the C standard library function <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_openpt()</span></code>. The <em>oflag</em>
|
||
argument is used to set file status flags and file access modes as
|
||
specified in the manual page of <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_openpt()</span></code> of your system.</p>
|
||
<p>The returned file descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.
|
||
If the value <a class="reference internal" href="#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_CLOEXEC</span></code></a> is available on the system, it is added to
|
||
<em>oflag</em>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.preadv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">preadv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffers</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.preadv" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Read from a file descriptor <em>fd</em> at a position of <em>offset</em> into mutable
|
||
<a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a> <em>buffers</em>, leaving the file
|
||
offset unchanged. Transfer data into each buffer until it is full and then
|
||
move on to the next buffer in the sequence to hold the rest of the data.</p>
|
||
<p>The flags argument contains a bitwise OR of zero or more of the following
|
||
flags:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.RWF_HIPRI" title="os.RWF_HIPRI"><code class="xref py py-data docutils literal notranslate"><span class="pre">RWF_HIPRI</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="#os.RWF_NOWAIT" title="os.RWF_NOWAIT"><code class="xref py py-data docutils literal notranslate"><span class="pre">RWF_NOWAIT</span></code></a></p></li>
|
||
</ul>
|
||
<p>Return the total number of bytes actually read which can be less than the
|
||
total capacity of all the objects.</p>
|
||
<p>The operating system may set a limit (<a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconf()</span></code></a> value
|
||
<code class="docutils literal notranslate"><span class="pre">'SC_IOV_MAX'</span></code>) on the number of buffers that can be used.</p>
|
||
<p>Combine the functionality of <a class="reference internal" href="#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readv()</span></code></a> and <a class="reference internal" href="#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pread()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.30, FreeBSD >= 6.0, OpenBSD >= 2.7, AIX >= 7.1.</p>
|
||
<p>Using flags requires Linux >= 4.6.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RWF_NOWAIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RWF_NOWAIT</span></span><a class="headerlink" href="#os.RWF_NOWAIT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Do not wait for data which is not immediately available. If this flag is
|
||
specified, the system call will return instantly if it would have to read
|
||
data from the backing storage or wait for a lock.</p>
|
||
<p>If some data was successfully read, it will return the number of bytes read.
|
||
If no bytes were read, it will return <code class="docutils literal notranslate"><span class="pre">-1</span></code> and set errno to
|
||
<a class="reference internal" href="errno.html#errno.EAGAIN" title="errno.EAGAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EAGAIN</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.14.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RWF_HIPRI">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RWF_HIPRI</span></span><a class="headerlink" href="#os.RWF_HIPRI" title="Link to this definition">¶</a></dt>
|
||
<dd><p>High priority read/write. Allows block-based filesystems to use polling
|
||
of the device, which provides lower latency, but may use additional
|
||
resources.</p>
|
||
<p>Currently, on Linux, this feature is usable only on a file descriptor opened
|
||
using the <a class="reference internal" href="#os.O_DIRECT" title="os.O_DIRECT"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_DIRECT</span></code></a> flag.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.6.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.ptsname">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">ptsname</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.ptsname" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the name of the slave pseudo-terminal device associated with the
|
||
master pseudo-terminal device to which the file descriptor <em>fd</em> refers.
|
||
The file descriptor <em>fd</em> is not closed upon failure.</p>
|
||
<p>Calls the reentrant C standard library function <code class="xref c c-func docutils literal notranslate"><span class="pre">ptsname_r()</span></code> if
|
||
it is available; otherwise, the C standard library function
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">ptsname()</span></code>, which is not guaranteed to be thread-safe, is called.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pwrite">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pwrite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pwrite" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Write the bytestring in <em>str</em> to file descriptor <em>fd</em> at position of
|
||
<em>offset</em>, leaving the file offset unchanged.</p>
|
||
<p>Return the number of bytes actually written.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pwritev">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pwritev</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffers</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pwritev" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Write the <em>buffers</em> contents to file descriptor <em>fd</em> at an offset <em>offset</em>,
|
||
leaving the file offset unchanged. <em>buffers</em> must be a sequence of
|
||
<a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a>. Buffers are processed in
|
||
array order. Entire contents of the first buffer is written before
|
||
proceeding to the second, and so on.</p>
|
||
<p>The flags argument contains a bitwise OR of zero or more of the following
|
||
flags:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.RWF_DSYNC" title="os.RWF_DSYNC"><code class="xref py py-data docutils literal notranslate"><span class="pre">RWF_DSYNC</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="#os.RWF_SYNC" title="os.RWF_SYNC"><code class="xref py py-data docutils literal notranslate"><span class="pre">RWF_SYNC</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="#os.RWF_APPEND" title="os.RWF_APPEND"><code class="xref py py-data docutils literal notranslate"><span class="pre">RWF_APPEND</span></code></a></p></li>
|
||
</ul>
|
||
<p>Return the total number of bytes actually written.</p>
|
||
<p>The operating system may set a limit (<a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconf()</span></code></a> value
|
||
<code class="docutils literal notranslate"><span class="pre">'SC_IOV_MAX'</span></code>) on the number of buffers that can be used.</p>
|
||
<p>Combine the functionality of <a class="reference internal" href="#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.writev()</span></code></a> and <a class="reference internal" href="#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pwrite()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.30, FreeBSD >= 6.0, OpenBSD >= 2.7, AIX >= 7.1.</p>
|
||
<p>Using flags requires Linux >= 4.6.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RWF_DSYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RWF_DSYNC</span></span><a class="headerlink" href="#os.RWF_DSYNC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Provide a per-write equivalent of the <a class="reference internal" href="#os.O_DSYNC" title="os.O_DSYNC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_DSYNC</span></code></a> <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> flag.
|
||
This flag effect applies only to the data range written by the system call.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.7.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RWF_SYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RWF_SYNC</span></span><a class="headerlink" href="#os.RWF_SYNC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Provide a per-write equivalent of the <a class="reference internal" href="#os.O_SYNC" title="os.O_SYNC"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_SYNC</span></code></a> <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> flag.
|
||
This flag effect applies only to the data range written by the system call.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.7.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RWF_APPEND">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RWF_APPEND</span></span><a class="headerlink" href="#os.RWF_APPEND" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Provide a per-write equivalent of the <a class="reference internal" href="#os.O_APPEND" title="os.O_APPEND"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_APPEND</span></code></a> <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a>
|
||
flag. This flag is meaningful only for <a class="reference internal" href="#os.pwritev" title="os.pwritev"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pwritev()</span></code></a>, and its
|
||
effect applies only to the data range written by the system call. The
|
||
<em>offset</em> argument does not affect the write operation; the data is always
|
||
appended to the end of the file. However, if the <em>offset</em> argument is
|
||
<code class="docutils literal notranslate"><span class="pre">-1</span></code>, the current file <em>offset</em> is updated.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 4.16.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.read">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.read" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>.</p>
|
||
<p>Return a bytestring containing the bytes read. If the end of the file
|
||
referred to by <em>fd</em> has been reached, an empty bytes object is returned.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function is intended for low-level I/O and must be applied to a file
|
||
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal notranslate"><span class="pre">pipe()</span></code></a>. To read a
|
||
“file object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or by
|
||
<a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or <a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdopen()</span></code></a>, or <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, use its
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">readline()</span></code> methods.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>If the system call is interrupted and the signal handler does not raise an
|
||
exception, the function now retries the system call instead of raising an
|
||
<a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> exception (see <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale).</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sendfile">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sendfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">out_fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">in_fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sendfile" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sendfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">out_fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">in_fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">headers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trailers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span></dt>
|
||
<dd><p>Copy <em>count</em> bytes from file descriptor <em>in_fd</em> to file descriptor <em>out_fd</em>
|
||
starting at <em>offset</em>.
|
||
Return the number of bytes sent. When EOF is reached return <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
|
||
<p>The first function notation is supported by all platforms that define
|
||
<a class="reference internal" href="#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>.</p>
|
||
<p>On Linux, if <em>offset</em> is given as <code class="docutils literal notranslate"><span class="pre">None</span></code>, the bytes are read from the
|
||
current position of <em>in_fd</em> and the position of <em>in_fd</em> is updated.</p>
|
||
<p>The second case may be used on macOS and FreeBSD where <em>headers</em> and
|
||
<em>trailers</em> are arbitrary sequences of buffers that are written before and
|
||
after the data from <em>in_fd</em> is written. It returns the same as the first case.</p>
|
||
<p>On macOS and FreeBSD, a value of <code class="docutils literal notranslate"><span class="pre">0</span></code> for <em>count</em> specifies to send until
|
||
the end of <em>in_fd</em> is reached.</p>
|
||
<p>All platforms support sockets as <em>out_fd</em> file descriptor, and some platforms
|
||
allow other types (e.g. regular file, pipe) as well.</p>
|
||
<p>Cross-platform applications should not use <em>headers</em>, <em>trailers</em> and <em>flags</em>
|
||
arguments.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>For a higher-level wrapper of <a class="reference internal" href="#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>, see
|
||
<a class="reference internal" href="socket.html#socket.socket.sendfile" title="socket.socket.sendfile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.sendfile()</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>Parameters <em>out</em> and <em>in</em> was renamed to <em>out_fd</em> and <em>in_fd</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SF_NODISKIO">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SF_NODISKIO</span></span><a class="headerlink" href="#os.SF_NODISKIO" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SF_MNOWAIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SF_MNOWAIT</span></span><a class="headerlink" href="#os.SF_MNOWAIT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SF_SYNC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SF_SYNC</span></span><a class="headerlink" href="#os.SF_SYNC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameters to the <a class="reference internal" href="#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a> function, if the implementation supports
|
||
them.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SF_NOCACHE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SF_NOCACHE</span></span><a class="headerlink" href="#os.SF_NOCACHE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Parameter to the <a class="reference internal" href="#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a> function, if the implementation supports
|
||
it. The data won’t be cached in the virtual memory and will be freed afterwards.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.11.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.set_blocking">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">set_blocking</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">blocking</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.set_blocking" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the blocking mode of the specified file descriptor. Set the
|
||
<a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> flag if blocking is <code class="docutils literal notranslate"><span class="pre">False</span></code>, clear the flag otherwise.</p>
|
||
<p>See also <a class="reference internal" href="#os.get_blocking" title="os.get_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_blocking()</span></code></a> and <a class="reference internal" href="socket.html#socket.socket.setblocking" title="socket.socket.setblocking"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.setblocking()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
<p>On Windows, this function is limited to pipes.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.5.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>Added support for pipes on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.splice">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">splice</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset_src</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset_dst</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.splice" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Transfer <em>count</em> bytes from file descriptor <em>src</em>, starting from offset
|
||
<em>offset_src</em>, to file descriptor <em>dst</em>, starting from offset <em>offset_dst</em>.
|
||
At least one of the file descriptors must refer to a pipe. If <em>offset_src</em>
|
||
is <code class="docutils literal notranslate"><span class="pre">None</span></code>, then <em>src</em> is read from the current position; respectively for
|
||
<em>offset_dst</em>. The offset associated to the file descriptor that refers to a
|
||
pipe must be <code class="docutils literal notranslate"><span class="pre">None</span></code>. The files pointed to by <em>src</em> and <em>dst</em> must reside in
|
||
the same filesystem, otherwise an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised with
|
||
<a class="reference internal" href="exceptions.html#OSError.errno" title="OSError.errno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">errno</span></code></a> set to <a class="reference internal" href="errno.html#errno.EXDEV" title="errno.EXDEV"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EXDEV</span></code></a>.</p>
|
||
<p>This copy is done without the additional cost of transferring data
|
||
from the kernel to user space and then back into the kernel. Additionally,
|
||
some filesystems could implement extra optimizations. The copy is done as if
|
||
both files are opened as binary.</p>
|
||
<p>Upon successful completion, returns the number of bytes spliced to or from
|
||
the pipe. A return value of 0 means end of input. If <em>src</em> refers to a
|
||
pipe, then this means that there was no data to transfer, and it would not
|
||
make sense to block because there are no writers connected to the write end
|
||
of the pipe.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.17 with glibc >= 2.5</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SPLICE_F_MOVE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SPLICE_F_MOVE</span></span><a class="headerlink" href="#os.SPLICE_F_MOVE" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SPLICE_F_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SPLICE_F_NONBLOCK</span></span><a class="headerlink" href="#os.SPLICE_F_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.SPLICE_F_MORE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SPLICE_F_MORE</span></span><a class="headerlink" href="#os.SPLICE_F_MORE" title="Link to this definition">¶</a></dt>
|
||
<dd><div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.readv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">readv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffers</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.readv" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Read from a file descriptor <em>fd</em> into a number of mutable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like
|
||
objects</span></a> <em>buffers</em>. Transfer data into each buffer until
|
||
it is full and then move on to the next buffer in the sequence to hold the
|
||
rest of the data.</p>
|
||
<p>Return the total number of bytes actually read which can be less than the
|
||
total capacity of all the objects.</p>
|
||
<p>The operating system may set a limit (<a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconf()</span></code></a> value
|
||
<code class="docutils literal notranslate"><span class="pre">'SC_IOV_MAX'</span></code>) on the number of buffers that can be used.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.tcgetpgrp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">tcgetpgrp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.tcgetpgrp" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the process group associated with the terminal given by <em>fd</em> (an open
|
||
file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a>).</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.tcsetpgrp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">tcsetpgrp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pg</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.tcsetpgrp" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the process group associated with the terminal given by <em>fd</em> (an open file
|
||
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a>) to <em>pg</em>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.ttyname">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">ttyname</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.ttyname" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a string which specifies the terminal device associated with
|
||
file descriptor <em>fd</em>. If <em>fd</em> is not associated with a terminal device, an
|
||
exception is raised.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.unlockpt">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">unlockpt</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.unlockpt" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Unlock the slave pseudo-terminal device associated with the master
|
||
pseudo-terminal device to which the file descriptor <em>fd</em> refers.
|
||
The file descriptor <em>fd</em> is not closed upon failure.</p>
|
||
<p>Calls the C standard library function <code class="xref c c-func docutils literal notranslate"><span class="pre">unlockpt()</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.write">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.write" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Write the bytestring in <em>str</em> to file descriptor <em>fd</em>.</p>
|
||
<p>Return the number of bytes actually written.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function is intended for low-level I/O and must be applied to a file
|
||
descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><code class="xref py py-func docutils literal notranslate"><span class="pre">pipe()</span></code></a>. To write a “file
|
||
object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> or
|
||
<a class="reference internal" href="#os.fdopen" title="os.fdopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdopen()</span></code></a>, or <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> or <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a>, use its
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> method.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>If the system call is interrupted and the signal handler does not raise an
|
||
exception, the function now retries the system call instead of raising an
|
||
<a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> exception (see <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale).</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.writev">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">writev</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffers</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.writev" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Write the contents of <em>buffers</em> to file descriptor <em>fd</em>. <em>buffers</em> must be
|
||
a sequence of <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a>. Buffers are
|
||
processed in array order. Entire contents of the first buffer is written
|
||
before proceeding to the second, and so on.</p>
|
||
<p>Returns the total number of bytes actually written.</p>
|
||
<p>The operating system may set a limit (<a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconf()</span></code></a> value
|
||
<code class="docutils literal notranslate"><span class="pre">'SC_IOV_MAX'</span></code>) on the number of buffers that can be used.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<section id="querying-the-size-of-a-terminal">
|
||
<span id="terminal-size"></span><h3>Querying the size of a terminal<a class="headerlink" href="#querying-the-size-of-a-terminal" title="Link to this heading">¶</a></h3>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.get_terminal_size">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">get_terminal_size</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">STDOUT_FILENO</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.get_terminal_size" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the size of the terminal window as <code class="docutils literal notranslate"><span class="pre">(columns,</span> <span class="pre">lines)</span></code>,
|
||
tuple of type <a class="reference internal" href="#os.terminal_size" title="os.terminal_size"><code class="xref py py-class docutils literal notranslate"><span class="pre">terminal_size</span></code></a>.</p>
|
||
<p>The optional argument <code class="docutils literal notranslate"><span class="pre">fd</span></code> (default <code class="docutils literal notranslate"><span class="pre">STDOUT_FILENO</span></code>, or standard
|
||
output) specifies which file descriptor should be queried.</p>
|
||
<p>If the file descriptor is not connected to a terminal, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>
|
||
is raised.</p>
|
||
<p><a class="reference internal" href="shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.get_terminal_size()</span></code></a> is the high-level function which
|
||
should normally be used, <code class="docutils literal notranslate"><span class="pre">os.get_terminal_size</span></code> is the low-level
|
||
implementation.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="os.terminal_size">
|
||
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">terminal_size</span></span><a class="headerlink" href="#os.terminal_size" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A subclass of tuple, holding <code class="docutils literal notranslate"><span class="pre">(columns,</span> <span class="pre">lines)</span></code> of the terminal window size.</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.terminal_size.columns">
|
||
<span class="sig-name descname"><span class="pre">columns</span></span><a class="headerlink" href="#os.terminal_size.columns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Width of the terminal window in characters.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.terminal_size.lines">
|
||
<span class="sig-name descname"><span class="pre">lines</span></span><a class="headerlink" href="#os.terminal_size.lines" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Height of the terminal window in characters.</p>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="inheritance-of-file-descriptors">
|
||
<span id="fd-inheritance"></span><h3>Inheritance of File Descriptors<a class="headerlink" href="#inheritance-of-file-descriptors" title="Link to this heading">¶</a></h3>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.4.</span></p>
|
||
</div>
|
||
<p>A file descriptor has an “inheritable” flag which indicates if the file descriptor
|
||
can be inherited by child processes. Since Python 3.4, file descriptors
|
||
created by Python are non-inheritable by default.</p>
|
||
<p>On UNIX, non-inheritable file descriptors are closed in child processes at the
|
||
execution of a new program, other file descriptors are inherited.</p>
|
||
<p>On Windows, non-inheritable handles and file descriptors are closed in child
|
||
processes, except for standard streams (file descriptors 0, 1 and 2: stdin, stdout
|
||
and stderr), which are always inherited. Using <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> functions,
|
||
all inheritable handles and all inheritable file descriptors are inherited.
|
||
Using the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module, all file descriptors except standard
|
||
streams are closed, and inheritable handles are only inherited if the
|
||
<em>close_fds</em> parameter is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<p>On WebAssembly platforms, the file descriptor cannot be modified.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.get_inheritable">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">get_inheritable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.get_inheritable" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the “inheritable” flag of the specified file descriptor (a boolean).</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.set_inheritable">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">set_inheritable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inheritable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.set_inheritable" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the “inheritable” flag of the specified file descriptor.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.get_handle_inheritable">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">get_handle_inheritable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">handle</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.get_handle_inheritable" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the “inheritable” flag of the specified handle (a boolean).</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.set_handle_inheritable">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">set_handle_inheritable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">handle</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inheritable</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.set_handle_inheritable" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the “inheritable” flag of the specified handle.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
</section>
|
||
<section id="files-and-directories">
|
||
<span id="os-file-dir"></span><h2>Files and Directories<a class="headerlink" href="#files-and-directories" title="Link to this heading">¶</a></h2>
|
||
<p>On some Unix platforms, many of these functions support one or more of these
|
||
features:</p>
|
||
<ul id="path-fd">
|
||
<li><p><strong>specifying a file descriptor:</strong>
|
||
Normally the <em>path</em> argument provided to functions in the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module
|
||
must be a string specifying a file path. However, some functions now
|
||
alternatively accept an open file descriptor for their <em>path</em> argument.
|
||
The function will then operate on the file referred to by the descriptor.
|
||
(For POSIX systems, Python will call the variant of the function prefixed
|
||
with <code class="docutils literal notranslate"><span class="pre">f</span></code> (e.g. call <code class="docutils literal notranslate"><span class="pre">fchdir</span></code> instead of <code class="docutils literal notranslate"><span class="pre">chdir</span></code>).)</p>
|
||
<p>You can check whether or not <em>path</em> can be specified as a file descriptor
|
||
for a particular function on your platform using <a class="reference internal" href="#os.supports_fd" title="os.supports_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_fd</span></code></a>.
|
||
If this functionality is unavailable, using it will raise a
|
||
<a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>.</p>
|
||
<p>If the function also supports <em>dir_fd</em> or <em>follow_symlinks</em> arguments, it’s
|
||
an error to specify one of those when supplying <em>path</em> as a file descriptor.</p>
|
||
</li>
|
||
</ul>
|
||
<ul id="dir-fd">
|
||
<li><p><strong>paths relative to directory descriptors:</strong> If <em>dir_fd</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it
|
||
should be a file descriptor referring to a directory, and the path to operate
|
||
on should be relative; path will then be relative to that directory. If the
|
||
path is absolute, <em>dir_fd</em> is ignored. (For POSIX systems, Python will call
|
||
the variant of the function with an <code class="docutils literal notranslate"><span class="pre">at</span></code> suffix and possibly prefixed with
|
||
<code class="docutils literal notranslate"><span class="pre">f</span></code> (e.g. call <code class="docutils literal notranslate"><span class="pre">faccessat</span></code> instead of <code class="docutils literal notranslate"><span class="pre">access</span></code>).</p>
|
||
<p>You can check whether or not <em>dir_fd</em> is supported for a particular function
|
||
on your platform using <a class="reference internal" href="#os.supports_dir_fd" title="os.supports_dir_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_dir_fd</span></code></a>. If it’s unavailable,
|
||
using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>.</p>
|
||
</li>
|
||
</ul>
|
||
<ul id="follow-symlinks">
|
||
<li><p><strong>not following symlinks:</strong> If <em>follow_symlinks</em> is
|
||
<code class="docutils literal notranslate"><span class="pre">False</span></code>, and the last element of the path to operate on is a symbolic link,
|
||
the function will operate on the symbolic link itself rather than the file
|
||
pointed to by the link. (For POSIX systems, Python will call the <code class="docutils literal notranslate"><span class="pre">l...</span></code>
|
||
variant of the function.)</p>
|
||
<p>You can check whether or not <em>follow_symlinks</em> is supported for a particular
|
||
function on your platform using <a class="reference internal" href="#os.supports_follow_symlinks" title="os.supports_follow_symlinks"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_follow_symlinks</span></code></a>.
|
||
If it’s unavailable, using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>.</p>
|
||
</li>
|
||
</ul>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.access">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">access</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">effective_ids</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.access" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Use the real uid/gid to test for access to <em>path</em>. Note that most operations
|
||
will use the effective uid/gid, therefore this routine can be used in a
|
||
suid/sgid environment to test if the invoking user has the specified access to
|
||
<em>path</em>. <em>mode</em> should be <a class="reference internal" href="#os.F_OK" title="os.F_OK"><code class="xref py py-const docutils literal notranslate"><span class="pre">F_OK</span></code></a> to test the existence of <em>path</em>, or it
|
||
can be the inclusive OR of one or more of <a class="reference internal" href="#os.R_OK" title="os.R_OK"><code class="xref py py-const docutils literal notranslate"><span class="pre">R_OK</span></code></a>, <a class="reference internal" href="#os.W_OK" title="os.W_OK"><code class="xref py py-const docutils literal notranslate"><span class="pre">W_OK</span></code></a>, and
|
||
<a class="reference internal" href="#os.X_OK" title="os.X_OK"><code class="xref py py-const docutils literal notranslate"><span class="pre">X_OK</span></code></a> to test permissions. Return <a class="reference internal" href="constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a> if access is allowed,
|
||
<a class="reference internal" href="constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> if not. See the Unix man page <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/access(2)">access(2)</a></em> for more
|
||
information.</p>
|
||
<p>This function can support specifying <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory
|
||
descriptors</span></a> and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p>If <em>effective_ids</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> will perform its access
|
||
checks using the effective uid/gid instead of the real uid/gid.
|
||
<em>effective_ids</em> may not be supported on your platform; you can check whether
|
||
or not it is available using <a class="reference internal" href="#os.supports_effective_ids" title="os.supports_effective_ids"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_effective_ids</span></code></a>. If it is
|
||
unavailable, using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Using <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> to check if a user is authorized to e.g. open a file
|
||
before actually doing so using <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> creates a security hole,
|
||
because the user might exploit the short time interval between checking
|
||
and opening the file to manipulate it. It’s preferable to use <a class="reference internal" href="../glossary.html#term-EAFP"><span class="xref std std-term">EAFP</span></a>
|
||
techniques. For example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="s2">"myfile"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">R_OK</span><span class="p">):</span>
|
||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"myfile"</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
|
||
<span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
<span class="k">return</span> <span class="s2">"some default data"</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>is better written as:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
|
||
<span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s2">"myfile"</span><span class="p">)</span>
|
||
<span class="k">except</span> <span class="ne">PermissionError</span><span class="p">:</span>
|
||
<span class="k">return</span> <span class="s2">"some default data"</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="k">with</span> <span class="n">fp</span><span class="p">:</span>
|
||
<span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>I/O operations may fail even when <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> indicates that they would
|
||
succeed, particularly for operations on network filesystems which may have
|
||
permissions semantics beyond the usual POSIX permission-bit model.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em>, <em>effective_ids</em>, and <em>follow_symlinks</em> parameters.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.F_OK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">F_OK</span></span><a class="headerlink" href="#os.F_OK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.R_OK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">R_OK</span></span><a class="headerlink" href="#os.R_OK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.W_OK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">W_OK</span></span><a class="headerlink" href="#os.W_OK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.X_OK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">X_OK</span></span><a class="headerlink" href="#os.X_OK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Values to pass as the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> to test the
|
||
existence, readability, writability and executability of <em>path</em>,
|
||
respectively.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.chdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.chdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-26">Change the current working directory to <em>path</em>.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>. The
|
||
descriptor must refer to an opened directory, not an open file.</p>
|
||
<p>This function can raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> and subclasses such as
|
||
<a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a>, <a class="reference internal" href="exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a>, and <a class="reference internal" href="exceptions.html#NotADirectoryError" title="NotADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotADirectoryError</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chdir</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as a file descriptor
|
||
on some platforms.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.chflags">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chflags</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.chflags" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination
|
||
(bitwise OR) of the following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module):</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_NODUMP" title="stat.UF_NODUMP"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_NODUMP</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_IMMUTABLE" title="stat.UF_IMMUTABLE"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_IMMUTABLE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_APPEND" title="stat.UF_APPEND"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_APPEND</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_OPAQUE" title="stat.UF_OPAQUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_OPAQUE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_NOUNLINK" title="stat.UF_NOUNLINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_NOUNLINK</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_COMPRESSED" title="stat.UF_COMPRESSED"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_COMPRESSED</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.UF_HIDDEN" title="stat.UF_HIDDEN"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.UF_HIDDEN</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.SF_ARCHIVED" title="stat.SF_ARCHIVED"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.SF_ARCHIVED</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.SF_IMMUTABLE" title="stat.SF_IMMUTABLE"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.SF_IMMUTABLE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.SF_APPEND" title="stat.SF_APPEND"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.SF_APPEND</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.SF_NOUNLINK" title="stat.SF_NOUNLINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.SF_NOUNLINK</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.SF_SNAPSHOT" title="stat.SF_SNAPSHOT"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.SF_SNAPSHOT</span></code></a></p></li>
|
||
</ul>
|
||
<p>This function can support <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chflags</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">flags</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>follow_symlinks</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.chmod">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.chmod" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one of the
|
||
following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module) or bitwise ORed
|
||
combinations of them:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_ISUID" title="stat.S_ISUID"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_ISUID</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_ISGID" title="stat.S_ISGID"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_ISGID</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_ENFMT" title="stat.S_ENFMT"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_ENFMT</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_ISVTX" title="stat.S_ISVTX"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_ISVTX</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IREAD" title="stat.S_IREAD"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IREAD</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IWRITE" title="stat.S_IWRITE"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IWRITE</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IEXEC" title="stat.S_IEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IEXEC</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IRWXU" title="stat.S_IRWXU"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IRWXU</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IRUSR" title="stat.S_IRUSR"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IRUSR</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IWUSR" title="stat.S_IWUSR"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IWUSR</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IXUSR" title="stat.S_IXUSR"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IXUSR</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IRWXG" title="stat.S_IRWXG"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IRWXG</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IRGRP" title="stat.S_IRGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IRGRP</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IWGRP" title="stat.S_IWGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IWGRP</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IXGRP" title="stat.S_IXGRP"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IXGRP</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IRWXO" title="stat.S_IRWXO"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IRWXO</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IROTH" title="stat.S_IROTH"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IROTH</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IWOTH" title="stat.S_IWOTH"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IWOTH</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="stat.html#stat.S_IXOTH" title="stat.S_IXOTH"><code class="xref py py-const docutils literal notranslate"><span class="pre">stat.S_IXOTH</span></code></a></p></li>
|
||
</ul>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>,
|
||
<a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a> and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not
|
||
following symlinks</span></a>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Although Windows supports <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>, you can only set the file’s
|
||
read-only flag with it (via the <code class="docutils literal notranslate"><span class="pre">stat.S_IWRITE</span></code> and <code class="docutils literal notranslate"><span class="pre">stat.S_IREAD</span></code>
|
||
constants or a corresponding integer value). All other bits are ignored.
|
||
The default value of <em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> on Windows.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chmod</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor,
|
||
and the <em>dir_fd</em> and <em>follow_symlinks</em> arguments.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>Added support for a file descriptor and the <em>follow_symlinks</em> argument
|
||
on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.chown">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chown</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gid</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.chown" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. To
|
||
leave one of the ids unchanged, set it to -1.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>,
|
||
<a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a> and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not
|
||
following symlinks</span></a>.</p>
|
||
<p>See <a class="reference internal" href="shutil.html#shutil.chown" title="shutil.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.chown()</span></code></a> for a higher-level function that accepts names in
|
||
addition to numeric ids.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chown</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">uid</span></code>, <code class="docutils literal notranslate"><span class="pre">gid</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor,
|
||
and the <em>dir_fd</em> and <em>follow_symlinks</em> arguments.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Supports a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.chroot">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">chroot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.chroot" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the root directory of the current process to <em>path</em>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fchdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fchdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fchdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the current working directory to the directory represented by the file
|
||
descriptor <em>fd</em>. The descriptor must refer to an opened directory, not an
|
||
open file. As of Python 3.3, this is equivalent to <code class="docutils literal notranslate"><span class="pre">os.chdir(fd)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chdir</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getcwd">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getcwd</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getcwd" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a string representing the current working directory.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getcwdb">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getcwdb</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getcwdb" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a bytestring representing the current working directory.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>The function now uses the UTF-8 encoding on Windows, rather than the ANSI
|
||
code page: see <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a> for the rationale. The function is no longer
|
||
deprecated on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lchflags">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lchflags</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchflags" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>, like <a class="reference internal" href="#os.chflags" title="os.chflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">chflags()</span></code></a>, but do
|
||
not follow symbolic links. As of Python 3.3, this is equivalent to
|
||
<code class="docutils literal notranslate"><span class="pre">os.chflags(path,</span> <span class="pre">flags,</span> <span class="pre">follow_symlinks=False)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chflags</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">flags</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lchmod">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lchmod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchmod" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this
|
||
affects the symlink rather than the target. See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>
|
||
for possible values of <em>mode</em>. As of Python 3.3, this is equivalent to
|
||
<code class="docutils literal notranslate"><span class="pre">os.chmod(path,</span> <span class="pre">mode,</span> <span class="pre">follow_symlinks=False)</span></code>.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">lchmod()</span></code> is not part of POSIX, but Unix implementations may have it if
|
||
changing the mode of symbolic links is supported.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chmod</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not Linux, FreeBSD >= 1.3, NetBSD >= 1.3, not OpenBSD</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>Added support on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lchown">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lchown</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gid</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lchown" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. This
|
||
function will not follow symbolic links. As of Python 3.3, this is equivalent
|
||
to <code class="docutils literal notranslate"><span class="pre">os.chown(path,</span> <span class="pre">uid,</span> <span class="pre">gid,</span> <span class="pre">follow_symlinks=False)</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.chown</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">uid</span></code>, <code class="docutils literal notranslate"><span class="pre">gid</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.link">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">link</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">src_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.link" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a hard link pointing to <em>src</em> named <em>dst</em>.</p>
|
||
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
|
||
supply <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>, and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not
|
||
following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.link</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">dst</span></code>, <code class="docutils literal notranslate"><span class="pre">src_dir_fd</span></code>, <code class="docutils literal notranslate"><span class="pre">dst_dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added Windows support.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>src_dir_fd</em>, <em>dst_dir_fd</em>, and <em>follow_symlinks</em> parameters.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>src</em> and <em>dst</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.listdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">listdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'.'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.listdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a list containing the names of the entries in the directory given by
|
||
<em>path</em>. The list is in arbitrary order, and does not include the special
|
||
entries <code class="docutils literal notranslate"><span class="pre">'.'</span></code> and <code class="docutils literal notranslate"><span class="pre">'..'</span></code> even if they are present in the directory.
|
||
If a file is removed from or added to the directory during the call of
|
||
this function, whether a name for that file be included is unspecified.</p>
|
||
<p><em>path</em> may be a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>. If <em>path</em> is of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code>
|
||
(directly or indirectly through the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface),
|
||
the filenames returned will also be of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code>;
|
||
in all other circumstances, they will be of type <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
|
||
<p>This function can also support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>; the file descriptor must refer to a directory.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.listdir</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>To encode <code class="docutils literal notranslate"><span class="pre">str</span></code> filenames to <code class="docutils literal notranslate"><span class="pre">bytes</span></code>, use <a class="reference internal" href="#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsencode()</span></code></a>.</p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> function returns directory entries along with
|
||
file attribute information, giving better performance for many
|
||
common use cases.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>The <em>path</em> parameter became optional.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.listdrives">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">listdrives</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.listdrives" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a list containing the names of drives on a Windows system.</p>
|
||
<p>A drive name typically looks like <code class="docutils literal notranslate"><span class="pre">'C:\\'</span></code>. Not every drive name
|
||
will be associated with a volume, and some may be inaccessible for
|
||
a variety of reasons, including permissions, network connectivity
|
||
or missing media. This function does not test for access.</p>
|
||
<p>May raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if an error occurs collecting the drive
|
||
names.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.listdrives</span></code> with no arguments.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.listmounts">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">listmounts</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">volume</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.listmounts" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a list containing the mount points for a volume on a Windows
|
||
system.</p>
|
||
<p><em>volume</em> must be represented as a GUID path, like those returned by
|
||
<a class="reference internal" href="#os.listvolumes" title="os.listvolumes"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listvolumes()</span></code></a>. Volumes may be mounted in multiple locations
|
||
or not at all. In the latter case, the list will be empty. Mount
|
||
points that are not associated with a volume will not be returned by
|
||
this function.</p>
|
||
<p>The mount points return by this function will be absolute paths, and
|
||
may be longer than the drive name.</p>
|
||
<p>Raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if the volume is not recognized or if an error
|
||
occurs collecting the paths.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.listmounts</span></code> with argument <code class="docutils literal notranslate"><span class="pre">volume</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.listvolumes">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">listvolumes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.listvolumes" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a list containing the volumes in the system.</p>
|
||
<p>Volumes are typically represented as a GUID path that looks like
|
||
<code class="docutils literal notranslate"><span class="pre">\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\</span></code>. Files can
|
||
usually be accessed through a GUID path, permissions allowing.
|
||
However, users are generally not familiar with them, and so the
|
||
recommended use of this function is to retrieve mount points
|
||
using <a class="reference internal" href="#os.listmounts" title="os.listmounts"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listmounts()</span></code></a>.</p>
|
||
<p>May raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if an error occurs collecting the volumes.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.listvolumes</span></code> with no arguments.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.lstat">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">lstat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.lstat" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Perform the equivalent of an <code class="xref c c-func docutils literal notranslate"><span class="pre">lstat()</span></code> system call on the given path.
|
||
Similar to <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>, but does not follow symbolic links. Return a
|
||
<a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a> object.</p>
|
||
<p>On platforms that do not support symbolic links, this is an alias for
|
||
<a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>.</p>
|
||
<p>As of Python 3.3, this is equivalent to <code class="docutils literal notranslate"><span class="pre">os.stat(path,</span> <span class="pre">dir_fd=dir_fd,</span>
|
||
<span class="pre">follow_symlinks=False)</span></code>.</p>
|
||
<p>This function can also support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a> function.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>On Windows, now opens reparse points that represent another path
|
||
(name surrogates), including symbolic links and directory junctions.
|
||
Other kinds of reparse points are resolved by the operating system as
|
||
for <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.mkdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">mkdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o777</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.mkdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>.</p>
|
||
<p>If the directory already exists, <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is raised. If a parent
|
||
directory in the path does not exist, <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is raised.</p>
|
||
<p id="mkdir-modebits">On some systems, <em>mode</em> is ignored. Where it is used, the current umask
|
||
value is first masked out. If bits other than the last 9 (i.e. the last 3
|
||
digits of the octal representation of the <em>mode</em>) are set, their meaning is
|
||
platform-dependent. On some platforms, they are ignored and you should call
|
||
<a class="reference internal" href="#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a> explicitly to set them.</p>
|
||
<p>On Windows, a <em>mode</em> of <code class="docutils literal notranslate"><span class="pre">0o700</span></code> is specifically handled to apply access
|
||
control to the new directory such that only the current user and
|
||
administrators have access. Other values of <em>mode</em> are ignored.</p>
|
||
<p>This function can also support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p>It is also possible to create temporary directories; see the
|
||
<a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tempfile</span></code></a> module’s <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> function.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.mkdir</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>Windows now handles a <em>mode</em> of <code class="docutils literal notranslate"><span class="pre">0o700</span></code>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.makedirs">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">makedirs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o777</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exist_ok</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.makedirs" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-28">Recursive directory creation function. Like <a class="reference internal" href="#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkdir()</span></code></a>, but makes all
|
||
intermediate-level directories needed to contain the leaf directory.</p>
|
||
<p>The <em>mode</em> parameter is passed to <a class="reference internal" href="#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkdir()</span></code></a> for creating the leaf
|
||
directory; see <a class="reference internal" href="#mkdir-modebits"><span class="std std-ref">the mkdir() description</span></a> for how it
|
||
is interpreted. To set the file permission bits of any newly created parent
|
||
directories you can set the umask before invoking <a class="reference internal" href="#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">makedirs()</span></code></a>. The
|
||
file permission bits of existing parent directories are not changed.</p>
|
||
<p>If <em>exist_ok</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> (the default), a <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is
|
||
raised if the target directory already exists.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p><a class="reference internal" href="#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">makedirs()</span></code></a> will become confused if the path elements to create
|
||
include <a class="reference internal" href="#os.pardir" title="os.pardir"><code class="xref py py-data docutils literal notranslate"><span class="pre">pardir</span></code></a> (eg. “..” on UNIX systems).</p>
|
||
</div>
|
||
<p>This function handles UNC paths correctly.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.mkdir</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <em>exist_ok</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4.1: </span>Before Python 3.4.1, if <em>exist_ok</em> was <code class="docutils literal notranslate"><span class="pre">True</span></code> and the directory existed,
|
||
<a class="reference internal" href="#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">makedirs()</span></code></a> would still raise an error if <em>mode</em> did not match the
|
||
mode of the existing directory. Since this behavior was impossible to
|
||
implement safely, it was removed in Python 3.4.1. See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21082">bpo-21082</a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>mode</em> argument no longer affects the file permission bits of
|
||
newly created intermediate-level directories.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.mkfifo">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">mkfifo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o666</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.mkfifo" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>.
|
||
The current umask value is first masked out from the mode.</p>
|
||
<p>This function can also support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p>FIFOs are pipes that can be accessed like regular files. FIFOs exist until they
|
||
are deleted (for example with <a class="reference internal" href="#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a>). Generally, FIFOs are used as
|
||
rendezvous between “client” and “server” type processes: the server opens the
|
||
FIFO for reading, and the client opens it for writing. Note that <a class="reference internal" href="#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkfifo()</span></code></a>
|
||
doesn’t open the FIFO — it just creates the rendezvous point.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.mknod">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">mknod</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0o600</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">device</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.mknod" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a filesystem node (file, device special file or named pipe) named
|
||
<em>path</em>. <em>mode</em> specifies both the permissions to use and the type of node
|
||
to be created, being combined (bitwise OR) with one of <code class="docutils literal notranslate"><span class="pre">stat.S_IFREG</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">stat.S_IFCHR</span></code>, <code class="docutils literal notranslate"><span class="pre">stat.S_IFBLK</span></code>, and <code class="docutils literal notranslate"><span class="pre">stat.S_IFIFO</span></code> (those constants are
|
||
available in <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a>). For <code class="docutils literal notranslate"><span class="pre">stat.S_IFCHR</span></code> and <code class="docutils literal notranslate"><span class="pre">stat.S_IFBLK</span></code>,
|
||
<em>device</em> defines the newly created device special file (probably using
|
||
<a class="reference internal" href="#os.makedev" title="os.makedev"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedev()</span></code></a>), otherwise it is ignored.</p>
|
||
<p>This function can also support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.major">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">major</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">device</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.major" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Extract the device major number from a raw device number (usually the
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">st_dev</span></code> or <code class="xref py py-attr docutils literal notranslate"><span class="pre">st_rdev</span></code> field from <code class="xref c c-struct docutils literal notranslate"><span class="pre">stat</span></code>).</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.minor">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">minor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">device</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.minor" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Extract the device minor number from a raw device number (usually the
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">st_dev</span></code> or <code class="xref py py-attr docutils literal notranslate"><span class="pre">st_rdev</span></code> field from <code class="xref c c-struct docutils literal notranslate"><span class="pre">stat</span></code>).</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.makedev">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">makedev</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">major</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minor</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.makedev" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Compose a raw device number from the major and minor device numbers.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pathconf">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pathconf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pathconf" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return system configuration information relevant to a named file. <em>name</em>
|
||
specifies the configuration value to retrieve; it may be a string which is the
|
||
name of a defined system value; these names are specified in a number of
|
||
standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define
|
||
additional names as well. The names known to the host operating system are
|
||
given in the <code class="docutils literal notranslate"><span class="pre">pathconf_names</span></code> dictionary. For configuration variables not
|
||
included in that mapping, passing an integer for <em>name</em> is also accepted.</p>
|
||
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. If a
|
||
specific value for <em>name</em> is not supported by the host system, even if it is
|
||
included in <code class="docutils literal notranslate"><span class="pre">pathconf_names</span></code>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised with
|
||
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.pathconf_names">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pathconf_names</span></span><a class="headerlink" href="#os.pathconf_names" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.pathconf" title="os.pathconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">pathconf()</span></code></a> and <a class="reference internal" href="#os.fpathconf" title="os.fpathconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">fpathconf()</span></code></a> to
|
||
the integer values defined for those names by the host operating system. This
|
||
can be used to determine the set of names known to the system.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.readlink">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">readlink</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.readlink" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a string representing the path to which the symbolic link points. The
|
||
result may be either an absolute or relative pathname; if it is relative, it
|
||
may be converted to an absolute pathname using
|
||
<code class="docutils literal notranslate"><span class="pre">os.path.join(os.path.dirname(path),</span> <span class="pre">result)</span></code>.</p>
|
||
<p>If the <em>path</em> is a string object (directly or indirectly through a
|
||
<a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface), the result will also be a string object,
|
||
and the call may raise a UnicodeDecodeError. If the <em>path</em> is a bytes
|
||
object (direct or indirectly), the result will be a bytes object.</p>
|
||
<p>This function can also support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p>When trying to resolve a path that may contain links, use
|
||
<a class="reference internal" href="os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">realpath()</span></code></a> to properly handle recursion and platform
|
||
differences.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> on Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> and a bytes object on Windows.</p>
|
||
<p>Added support for directory junctions, and changed to return the
|
||
substitution path (which typically includes <code class="docutils literal notranslate"><span class="pre">\\?\</span></code> prefix) rather
|
||
than the optional “print name” field that was previously returned.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.remove">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">remove</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.remove" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Remove (delete) the file <em>path</em>. If <em>path</em> is a directory, an
|
||
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised. Use <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a> to remove directories.
|
||
If the file does not exist, a <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is raised.</p>
|
||
<p>This function can support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p>On Windows, attempting to remove a file that is in use causes an exception to
|
||
be raised; on Unix, the directory entry is removed but the storage allocated
|
||
to the file is not made available until the original file is no longer in use.</p>
|
||
<p>This function is semantically identical to <a class="reference internal" href="#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">unlink()</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.remove</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.removedirs">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">removedirs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.removedirs" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-29">Remove directories recursively. Works like <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a> except that, if the
|
||
leaf directory is successfully removed, <a class="reference internal" href="#os.removedirs" title="os.removedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">removedirs()</span></code></a> tries to
|
||
successively remove every parent directory mentioned in <em>path</em> until an error
|
||
is raised (which is ignored, because it generally means that a parent directory
|
||
is not empty). For example, <code class="docutils literal notranslate"><span class="pre">os.removedirs('foo/bar/baz')</span></code> will first remove
|
||
the directory <code class="docutils literal notranslate"><span class="pre">'foo/bar/baz'</span></code>, and then remove <code class="docutils literal notranslate"><span class="pre">'foo/bar'</span></code> and <code class="docutils literal notranslate"><span class="pre">'foo'</span></code> if
|
||
they are empty. Raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if the leaf directory could not be
|
||
successfully removed.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.remove</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.rename">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">rename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">src_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.rename" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>. If <em>dst</em> exists, the operation
|
||
will fail with an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> subclass in a number of cases:</p>
|
||
<p>On Windows, if <em>dst</em> exists a <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is always raised.
|
||
The operation may fail if <em>src</em> and <em>dst</em> are on different filesystems. Use
|
||
<a class="reference internal" href="shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.move()</span></code></a> to support moves to a different filesystem.</p>
|
||
<p>On Unix, if <em>src</em> is a file and <em>dst</em> is a directory or vice-versa, an
|
||
<a class="reference internal" href="exceptions.html#IsADirectoryError" title="IsADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IsADirectoryError</span></code></a> or a <a class="reference internal" href="exceptions.html#NotADirectoryError" title="NotADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotADirectoryError</span></code></a> will be raised
|
||
respectively. If both are directories and <em>dst</em> is empty, <em>dst</em> will be
|
||
silently replaced. If <em>dst</em> is a non-empty directory, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>
|
||
is raised. If both are files, <em>dst</em> will be replaced silently if the user
|
||
has permission. The operation may fail on some Unix flavors if <em>src</em> and
|
||
<em>dst</em> are on different filesystems. If successful, the renaming will be an
|
||
atomic operation (this is a POSIX requirement).</p>
|
||
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
|
||
supply <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p>If you want cross-platform overwriting of the destination, use <a class="reference internal" href="#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">replace()</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.rename</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">dst</span></code>, <code class="docutils literal notranslate"><span class="pre">src_dir_fd</span></code>, <code class="docutils literal notranslate"><span class="pre">dst_dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>src_dir_fd</em> and <em>dst_dir_fd</em> parameters.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>src</em> and <em>dst</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.renames">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">renames</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">old</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">new</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.renames" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Recursive directory or file renaming function. Works like <a class="reference internal" href="#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">rename()</span></code></a>, except
|
||
creation of any intermediate directories needed to make the new pathname good is
|
||
attempted first. After the rename, directories corresponding to rightmost path
|
||
segments of the old name will be pruned away using <a class="reference internal" href="#os.removedirs" title="os.removedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">removedirs()</span></code></a>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This function can fail with the new directory structure made if you lack
|
||
permissions needed to remove the leaf directory or file.</p>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.rename</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">dst</span></code>, <code class="docutils literal notranslate"><span class="pre">src_dir_fd</span></code>, <code class="docutils literal notranslate"><span class="pre">dst_dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>old</em> and <em>new</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.replace">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">replace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">src_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst_dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.replace" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Rename the file or directory <em>src</em> to <em>dst</em>. If <em>dst</em> is a non-empty directory,
|
||
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> will be raised. If <em>dst</em> exists and is a file, it will
|
||
be replaced silently if the user has permission. The operation may fail
|
||
if <em>src</em> and <em>dst</em> are on different filesystems. If successful,
|
||
the renaming will be an atomic operation (this is a POSIX requirement).</p>
|
||
<p>This function can support specifying <em>src_dir_fd</em> and/or <em>dst_dir_fd</em> to
|
||
supply <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.rename</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">dst</span></code>, <code class="docutils literal notranslate"><span class="pre">src_dir_fd</span></code>, <code class="docutils literal notranslate"><span class="pre">dst_dir_fd</span></code>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>src</em> and <em>dst</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.rmdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">rmdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.rmdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Remove (delete) the directory <em>path</em>. If the directory does not exist or is
|
||
not empty, a <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> or an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised
|
||
respectively. In order to remove whole directory trees,
|
||
<a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> can be used.</p>
|
||
<p>This function can support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.rmdir</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.scandir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">scandir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'.'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.scandir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return an iterator of <a class="reference internal" href="#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> objects corresponding to the
|
||
entries in the directory given by <em>path</em>. The entries are yielded in
|
||
arbitrary order, and the special entries <code class="docutils literal notranslate"><span class="pre">'.'</span></code> and <code class="docutils literal notranslate"><span class="pre">'..'</span></code> are not
|
||
included. If a file is removed from or added to the directory after
|
||
creating the iterator, whether an entry for that file be included is
|
||
unspecified.</p>
|
||
<p>Using <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> instead of <a class="reference internal" href="#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">listdir()</span></code></a> can significantly
|
||
increase the performance of code that also needs file type or file
|
||
attribute information, because <a class="reference internal" href="#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> objects expose this
|
||
information if the operating system provides it when scanning a directory.
|
||
All <a class="reference internal" href="#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> methods may perform a system call, but
|
||
<a class="reference internal" href="#os.DirEntry.is_dir" title="os.DirEntry.is_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_dir()</span></code></a> and <a class="reference internal" href="#os.DirEntry.is_file" title="os.DirEntry.is_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_file()</span></code></a> usually only
|
||
require a system call for symbolic links; <a class="reference internal" href="#os.DirEntry.stat" title="os.DirEntry.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.DirEntry.stat()</span></code></a>
|
||
always requires a system call on Unix but only requires one for
|
||
symbolic links on Windows.</p>
|
||
<p><em>path</em> may be a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>. If <em>path</em> is of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code>
|
||
(directly or indirectly through the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface),
|
||
the type of the <a class="reference internal" href="#os.DirEntry.name" title="os.DirEntry.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> and <a class="reference internal" href="#os.DirEntry.path" title="os.DirEntry.path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code></a>
|
||
attributes of each <a class="reference internal" href="#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> will be <code class="docutils literal notranslate"><span class="pre">bytes</span></code>; in all other
|
||
circumstances, they will be of type <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
|
||
<p>This function can also support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>; the file descriptor must refer to a directory.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.scandir</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<p>The <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> iterator supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol
|
||
and has the following method:</p>
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.scandir.close">
|
||
<span class="sig-prename descclassname"><span class="pre">scandir.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.scandir.close" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Close the iterator and free acquired resources.</p>
|
||
<p>This is called automatically when the iterator is exhausted or garbage
|
||
collected, or when an error happens during iterating. However it
|
||
is advisable to call it explicitly or use the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a>
|
||
statement.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>The following example shows a simple use of <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> to display all
|
||
the files (excluding directories) in the given <em>path</em> that don’t start with
|
||
<code class="docutils literal notranslate"><span class="pre">'.'</span></code>. The <code class="docutils literal notranslate"><span class="pre">entry.is_file()</span></code> call will generally not make an additional
|
||
system call:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">os</span><span class="o">.</span><span class="n">scandir</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="k">as</span> <span class="n">it</span><span class="p">:</span>
|
||
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">it</span><span class="p">:</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span> <span class="ow">and</span> <span class="n">entry</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On Unix-based systems, <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> uses the system’s
|
||
<a class="reference external" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/opendir.html">opendir()</a>
|
||
and
|
||
<a class="reference external" href="https://pubs.opengroup.org/onlinepubs/009695399/functions/readdir_r.html">readdir()</a>
|
||
functions. On Windows, it uses the Win32
|
||
<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx">FindFirstFileW</a>
|
||
and
|
||
<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx">FindNextFileW</a>
|
||
functions.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.5.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Added support for the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol and the
|
||
<a class="reference internal" href="#os.scandir.close" title="os.scandir.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">close()</span></code></a> method. If a <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> iterator is neither
|
||
exhausted nor explicitly closed a <a class="reference internal" href="exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> will be emitted
|
||
in its destructor.</p>
|
||
<p>The function accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>Added support for <a class="reference internal" href="#path-fd"><span class="std std-ref">file descriptors</span></a> on Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="os.DirEntry">
|
||
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">DirEntry</span></span><a class="headerlink" href="#os.DirEntry" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Object yielded by <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> to expose the file path and other file
|
||
attributes of a directory entry.</p>
|
||
<p><a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> will provide as much of this information as possible without
|
||
making additional system calls. When a <code class="docutils literal notranslate"><span class="pre">stat()</span></code> or <code class="docutils literal notranslate"><span class="pre">lstat()</span></code> system call
|
||
is made, the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object will cache the result.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> instances are not intended to be stored in long-lived data
|
||
structures; if you know the file metadata has changed or if a long time has
|
||
elapsed since calling <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a>, call <code class="docutils literal notranslate"><span class="pre">os.stat(entry.path)</span></code> to fetch
|
||
up-to-date information.</p>
|
||
<p>Because the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> methods can make operating system calls, they may
|
||
also raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>. If you need very fine-grained
|
||
control over errors, you can catch <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> when calling one of the
|
||
<code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> methods and handle as appropriate.</p>
|
||
<p>To be directly usable as a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>, <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code>
|
||
implements the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface.</p>
|
||
<p>Attributes and methods on a <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> instance are as follows:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.DirEntry.name">
|
||
<span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#os.DirEntry.name" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The entry’s base filename, relative to the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> <em>path</em>
|
||
argument.</p>
|
||
<p>The <a class="reference internal" href="#os.name" title="os.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute will be <code class="docutils literal notranslate"><span class="pre">bytes</span></code> if the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a>
|
||
<em>path</em> argument is of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code> and <code class="docutils literal notranslate"><span class="pre">str</span></code> otherwise. Use
|
||
<a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsdecode()</span></code></a> to decode byte filenames.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.DirEntry.path">
|
||
<span class="sig-name descname"><span class="pre">path</span></span><a class="headerlink" href="#os.DirEntry.path" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The entry’s full path name: equivalent to <code class="docutils literal notranslate"><span class="pre">os.path.join(scandir_path,</span>
|
||
<span class="pre">entry.name)</span></code> where <em>scandir_path</em> is the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> <em>path</em>
|
||
argument. The path is only absolute if the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> <em>path</em>
|
||
argument was absolute. If the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> <em>path</em>
|
||
argument was a <a class="reference internal" href="#path-fd"><span class="std std-ref">file descriptor</span></a>, the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code></a>
|
||
attribute is the same as the <a class="reference internal" href="#os.name" title="os.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute.</p>
|
||
<p>The <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code></a> attribute will be <code class="docutils literal notranslate"><span class="pre">bytes</span></code> if the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a>
|
||
<em>path</em> argument is of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code> and <code class="docutils literal notranslate"><span class="pre">str</span></code> otherwise. Use
|
||
<a class="reference internal" href="#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsdecode()</span></code></a> to decode byte filenames.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.inode">
|
||
<span class="sig-name descname"><span class="pre">inode</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.inode" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the inode number of the entry.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object. Use
|
||
<code class="docutils literal notranslate"><span class="pre">os.stat(entry.path,</span> <span class="pre">follow_symlinks=False).st_ino</span></code> to fetch up-to-date
|
||
information.</p>
|
||
<p>On the first, uncached call, a system call is required on Windows but
|
||
not on Unix.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.is_dir">
|
||
<span class="sig-name descname"><span class="pre">is_dir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.is_dir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if this entry is a directory or a symbolic link pointing
|
||
to a directory; return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the entry is or points to any other
|
||
kind of file, or if it doesn’t exist anymore.</p>
|
||
<p>If <em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, return <code class="docutils literal notranslate"><span class="pre">True</span></code> only if this entry
|
||
is a directory (without following symlinks); return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the
|
||
entry is any other kind of file or if it doesn’t exist anymore.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object, with a separate cache
|
||
for <em>follow_symlinks</em> <code class="docutils literal notranslate"><span class="pre">True</span></code> and <code class="docutils literal notranslate"><span class="pre">False</span></code>. Call <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> along
|
||
with <a class="reference internal" href="stat.html#stat.S_ISDIR" title="stat.S_ISDIR"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat.S_ISDIR()</span></code></a> to fetch up-to-date information.</p>
|
||
<p>On the first, uncached call, no system call is required in most cases.
|
||
Specifically, for non-symlinks, neither Windows or Unix require a system
|
||
call, except on certain Unix file systems, such as network file systems,
|
||
that return <code class="docutils literal notranslate"><span class="pre">dirent.d_type</span> <span class="pre">==</span> <span class="pre">DT_UNKNOWN</span></code>. If the entry is a symlink,
|
||
a system call will be required to follow the symlink unless
|
||
<em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<p>This method can raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, such as <a class="reference internal" href="exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a>,
|
||
but <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is caught and not raised.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.is_file">
|
||
<span class="sig-name descname"><span class="pre">is_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.is_file" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if this entry is a file or a symbolic link pointing to a
|
||
file; return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the entry is or points to a directory or other
|
||
non-file entry, or if it doesn’t exist anymore.</p>
|
||
<p>If <em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, return <code class="docutils literal notranslate"><span class="pre">True</span></code> only if this entry
|
||
is a file (without following symlinks); return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the entry is
|
||
a directory or other non-file entry, or if it doesn’t exist anymore.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object. Caching, system calls
|
||
made, and exceptions raised are as per <a class="reference internal" href="#os.DirEntry.is_dir" title="os.DirEntry.is_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_dir()</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.is_symlink">
|
||
<span class="sig-name descname"><span class="pre">is_symlink</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.is_symlink" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if this entry is a symbolic link (even if broken);
|
||
return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the entry points to a directory or any kind of file,
|
||
or if it doesn’t exist anymore.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object. Call
|
||
<a class="reference internal" href="os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.islink()</span></code></a> to fetch up-to-date information.</p>
|
||
<p>On the first, uncached call, no system call is required in most cases.
|
||
Specifically, neither Windows or Unix require a system call, except on
|
||
certain Unix file systems, such as network file systems, that return
|
||
<code class="docutils literal notranslate"><span class="pre">dirent.d_type</span> <span class="pre">==</span> <span class="pre">DT_UNKNOWN</span></code>.</p>
|
||
<p>This method can raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, such as <a class="reference internal" href="exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a>,
|
||
but <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is caught and not raised.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.is_junction">
|
||
<span class="sig-name descname"><span class="pre">is_junction</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.is_junction" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if this entry is a junction (even if broken);
|
||
return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the entry points to a regular directory, any kind
|
||
of file, a symlink, or if it doesn’t exist anymore.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object. Call
|
||
<a class="reference internal" href="os.path.html#os.path.isjunction" title="os.path.isjunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isjunction()</span></code></a> to fetch up-to-date information.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt class="sig sig-object py" id="os.DirEntry.stat">
|
||
<span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.DirEntry.stat" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a> object for this entry. This method
|
||
follows symbolic links by default; to stat a symbolic link add the
|
||
<code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code> argument.</p>
|
||
<p>On Unix, this method always requires a system call. On Windows, it
|
||
only requires a system call if <em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> and the
|
||
entry is a reparse point (for example, a symbolic link or directory
|
||
junction).</p>
|
||
<p>On Windows, the <code class="docutils literal notranslate"><span class="pre">st_ino</span></code>, <code class="docutils literal notranslate"><span class="pre">st_dev</span></code> and <code class="docutils literal notranslate"><span class="pre">st_nlink</span></code> attributes of the
|
||
<a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a> are always set to zero. Call <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> to
|
||
get these attributes.</p>
|
||
<p>The result is cached on the <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> object, with a separate cache
|
||
for <em>follow_symlinks</em> <code class="docutils literal notranslate"><span class="pre">True</span></code> and <code class="docutils literal notranslate"><span class="pre">False</span></code>. Call <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> to
|
||
fetch up-to-date information.</p>
|
||
</dd></dl>
|
||
|
||
<p>Note that there is a nice correspondence between several attributes
|
||
and methods of <code class="docutils literal notranslate"><span class="pre">os.DirEntry</span></code> and of <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>. In
|
||
particular, the <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute has the same
|
||
meaning, as do the <code class="docutils literal notranslate"><span class="pre">is_dir()</span></code>, <code class="docutils literal notranslate"><span class="pre">is_file()</span></code>, <code class="docutils literal notranslate"><span class="pre">is_symlink()</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">is_junction()</span></code>, and <code class="docutils literal notranslate"><span class="pre">stat()</span></code> methods.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.5.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Added support for the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface. Added support
|
||
for <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> paths on Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>The <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> attribute of a stat result is deprecated on Windows.
|
||
The file creation time is properly available as <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code>, and
|
||
in the future <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> may be changed to return zero or the
|
||
metadata change time, if available.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.stat">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.stat" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the status of a file or a file descriptor. Perform the equivalent of a
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">stat()</span></code> system call on the given path. <em>path</em> may be specified as
|
||
either a string or bytes – directly or indirectly through the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a>
|
||
interface – or as an open file descriptor. Return a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a>
|
||
object.</p>
|
||
<p>This function normally follows symlinks; to stat a symlink add the argument
|
||
<code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code>, or use <a class="reference internal" href="#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a>.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a> and
|
||
<a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p>On Windows, passing <code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code> will disable following all
|
||
name-surrogate reparse points, which includes symlinks and directory
|
||
junctions. Other types of reparse points that do not resemble links or that
|
||
the operating system is unable to follow will be opened directly. When
|
||
following a chain of multiple links, this may result in the original link
|
||
being returned instead of the non-link that prevented full traversal. To
|
||
obtain stat results for the final path in this case, use the
|
||
<a class="reference internal" href="os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.realpath()</span></code></a> function to resolve the path name as far as
|
||
possible and call <a class="reference internal" href="#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a> on the result. This does not apply to
|
||
dangling symlinks or junction points, which will raise the usual exceptions.</p>
|
||
<p id="index-30">Example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="gp">>>> </span><span class="n">statinfo</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s1">'somefile.txt'</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">statinfo</span>
|
||
<span class="go">os.stat_result(st_mode=33188, st_ino=7876932, st_dev=234881026,</span>
|
||
<span class="go">st_nlink=1, st_uid=501, st_gid=501, st_size=264, st_atime=1297230295,</span>
|
||
<span class="go">st_mtime=1297230027, st_ctime=1297230027)</span>
|
||
<span class="gp">>>> </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span>
|
||
<span class="go">264</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><a class="reference internal" href="#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstat()</span></code></a> and <a class="reference internal" href="#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a> functions.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> and <em>follow_symlinks</em> parameters,
|
||
specifying a file descriptor instead of a path.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>On Windows, all reparse points that can be resolved by the operating
|
||
system are now followed, and passing <code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code>
|
||
disables following all name surrogate reparse points. If the operating
|
||
system reaches a reparse point that it is not able to follow, <em>stat</em> now
|
||
returns the information for the original path as if
|
||
<code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code> had been specified instead of raising an error.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="os.stat_result">
|
||
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">stat_result</span></span><a class="headerlink" href="#os.stat_result" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Object whose attributes correspond roughly to the members of the
|
||
<code class="xref c c-struct docutils literal notranslate"><span class="pre">stat</span></code> structure. It is used for the result of <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>,
|
||
<a class="reference internal" href="#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fstat()</span></code></a> and <a class="reference internal" href="#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a>.</p>
|
||
<p>Attributes:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_mode">
|
||
<span class="sig-name descname"><span class="pre">st_mode</span></span><a class="headerlink" href="#os.stat_result.st_mode" title="Link to this definition">¶</a></dt>
|
||
<dd><p>File mode: file type and file mode bits (permissions).</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_ino">
|
||
<span class="sig-name descname"><span class="pre">st_ino</span></span><a class="headerlink" href="#os.stat_result.st_ino" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Platform dependent, but if non-zero, uniquely identifies the
|
||
file for a given value of <code class="docutils literal notranslate"><span class="pre">st_dev</span></code>. Typically:</p>
|
||
<ul class="simple">
|
||
<li><p>the inode number on Unix,</p></li>
|
||
<li><p>the <a class="reference external" href="https://msdn.microsoft.com/en-us/library/aa363788">file index</a> on
|
||
Windows</p></li>
|
||
</ul>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_dev">
|
||
<span class="sig-name descname"><span class="pre">st_dev</span></span><a class="headerlink" href="#os.stat_result.st_dev" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Identifier of the device on which this file resides.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_nlink">
|
||
<span class="sig-name descname"><span class="pre">st_nlink</span></span><a class="headerlink" href="#os.stat_result.st_nlink" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Number of hard links.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_uid">
|
||
<span class="sig-name descname"><span class="pre">st_uid</span></span><a class="headerlink" href="#os.stat_result.st_uid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>User identifier of the file owner.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_gid">
|
||
<span class="sig-name descname"><span class="pre">st_gid</span></span><a class="headerlink" href="#os.stat_result.st_gid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Group identifier of the file owner.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_size">
|
||
<span class="sig-name descname"><span class="pre">st_size</span></span><a class="headerlink" href="#os.stat_result.st_size" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Size of the file in bytes, if it is a regular file or a symbolic link.
|
||
The size of a symbolic link is the length of the pathname it contains,
|
||
without a terminating null byte.</p>
|
||
</dd></dl>
|
||
|
||
<p>Timestamps:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_atime">
|
||
<span class="sig-name descname"><span class="pre">st_atime</span></span><a class="headerlink" href="#os.stat_result.st_atime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent access expressed in seconds.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_mtime">
|
||
<span class="sig-name descname"><span class="pre">st_mtime</span></span><a class="headerlink" href="#os.stat_result.st_mtime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent content modification expressed in seconds.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_ctime">
|
||
<span class="sig-name descname"><span class="pre">st_ctime</span></span><a class="headerlink" href="#os.stat_result.st_ctime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent metadata change expressed in seconds.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span><code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> is deprecated on Windows. Use <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code> for
|
||
the file creation time. In the future, <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> will contain
|
||
the time of the most recent metadata change, as for other platforms.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_atime_ns">
|
||
<span class="sig-name descname"><span class="pre">st_atime_ns</span></span><a class="headerlink" href="#os.stat_result.st_atime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent access expressed in nanoseconds as an integer.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_mtime_ns">
|
||
<span class="sig-name descname"><span class="pre">st_mtime_ns</span></span><a class="headerlink" href="#os.stat_result.st_mtime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent content modification expressed in nanoseconds as an
|
||
integer.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_ctime_ns">
|
||
<span class="sig-name descname"><span class="pre">st_ctime_ns</span></span><a class="headerlink" href="#os.stat_result.st_ctime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of most recent metadata change expressed in nanoseconds as an
|
||
integer.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span><code class="docutils literal notranslate"><span class="pre">st_ctime_ns</span></code> is deprecated on Windows. Use <code class="docutils literal notranslate"><span class="pre">st_birthtime_ns</span></code>
|
||
for the file creation time. In the future, <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> will contain
|
||
the time of the most recent metadata change, as for other platforms.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_birthtime">
|
||
<span class="sig-name descname"><span class="pre">st_birthtime</span></span><a class="headerlink" href="#os.stat_result.st_birthtime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of file creation expressed in seconds. This attribute is not
|
||
always available, and may raise <a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span><code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code> is now available on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_birthtime_ns">
|
||
<span class="sig-name descname"><span class="pre">st_birthtime_ns</span></span><a class="headerlink" href="#os.stat_result.st_birthtime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Time of file creation expressed in nanoseconds as an integer.
|
||
This attribute is not always available, and may raise
|
||
<a class="reference internal" href="exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>The exact meaning and resolution of the <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime</span></code></a>,
|
||
<a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime</span></code></a>, <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime</span></code></a> and <a class="reference internal" href="#os.stat_result.st_birthtime" title="os.stat_result.st_birthtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime</span></code></a> attributes
|
||
depend on the operating system and the file system. For example, on
|
||
Windows systems using the FAT32 file systems, <a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime</span></code></a> has
|
||
2-second resolution, and <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime</span></code></a> has only 1-day resolution.
|
||
See your operating system documentation for details.</p>
|
||
<p>Similarly, although <a class="reference internal" href="#os.stat_result.st_atime_ns" title="os.stat_result.st_atime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime_ns</span></code></a>, <a class="reference internal" href="#os.stat_result.st_mtime_ns" title="os.stat_result.st_mtime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime_ns</span></code></a>,
|
||
<a class="reference internal" href="#os.stat_result.st_ctime_ns" title="os.stat_result.st_ctime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime_ns</span></code></a> and <a class="reference internal" href="#os.stat_result.st_birthtime_ns" title="os.stat_result.st_birthtime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime_ns</span></code></a> are always expressed in
|
||
nanoseconds, many systems do not provide nanosecond precision. On
|
||
systems that do provide nanosecond precision, the floating-point object
|
||
used to store <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime</span></code></a>, <a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime</span></code></a>, <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime</span></code></a> and
|
||
<a class="reference internal" href="#os.stat_result.st_birthtime" title="os.stat_result.st_birthtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime</span></code></a> cannot preserve all of it, and as such will be
|
||
slightly inexact. If you need the exact timestamps you should always use
|
||
<a class="reference internal" href="#os.stat_result.st_atime_ns" title="os.stat_result.st_atime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime_ns</span></code></a>, <a class="reference internal" href="#os.stat_result.st_mtime_ns" title="os.stat_result.st_mtime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime_ns</span></code></a>, <a class="reference internal" href="#os.stat_result.st_ctime_ns" title="os.stat_result.st_ctime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime_ns</span></code></a> and
|
||
<a class="reference internal" href="#os.stat_result.st_birthtime_ns" title="os.stat_result.st_birthtime_ns"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime_ns</span></code></a>.</p>
|
||
</div>
|
||
<p>On some Unix systems (such as Linux), the following attributes may also be
|
||
available:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_blocks">
|
||
<span class="sig-name descname"><span class="pre">st_blocks</span></span><a class="headerlink" href="#os.stat_result.st_blocks" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Number of 512-byte blocks allocated for file.
|
||
This may be smaller than <a class="reference internal" href="#os.stat_result.st_size" title="os.stat_result.st_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_size</span></code></a>/512 when the file has holes.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_blksize">
|
||
<span class="sig-name descname"><span class="pre">st_blksize</span></span><a class="headerlink" href="#os.stat_result.st_blksize" title="Link to this definition">¶</a></dt>
|
||
<dd><p>“Preferred” blocksize for efficient file system I/O. Writing to a file in
|
||
smaller chunks may cause an inefficient read-modify-rewrite.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_rdev">
|
||
<span class="sig-name descname"><span class="pre">st_rdev</span></span><a class="headerlink" href="#os.stat_result.st_rdev" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Type of device if an inode device.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_flags">
|
||
<span class="sig-name descname"><span class="pre">st_flags</span></span><a class="headerlink" href="#os.stat_result.st_flags" title="Link to this definition">¶</a></dt>
|
||
<dd><p>User defined flags for file.</p>
|
||
</dd></dl>
|
||
|
||
<p>On other Unix systems (such as FreeBSD), the following attributes may be
|
||
available (but may be only filled out if root tries to use them):</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_gen">
|
||
<span class="sig-name descname"><span class="pre">st_gen</span></span><a class="headerlink" href="#os.stat_result.st_gen" title="Link to this definition">¶</a></dt>
|
||
<dd><p>File generation number.</p>
|
||
</dd></dl>
|
||
|
||
<p>On Solaris and derivatives, the following attributes may also be
|
||
available:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_fstype">
|
||
<span class="sig-name descname"><span class="pre">st_fstype</span></span><a class="headerlink" href="#os.stat_result.st_fstype" title="Link to this definition">¶</a></dt>
|
||
<dd><p>String that uniquely identifies the type of the filesystem that
|
||
contains the file.</p>
|
||
</dd></dl>
|
||
|
||
<p>On macOS systems, the following attributes may also be available:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_rsize">
|
||
<span class="sig-name descname"><span class="pre">st_rsize</span></span><a class="headerlink" href="#os.stat_result.st_rsize" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Real size of the file.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_creator">
|
||
<span class="sig-name descname"><span class="pre">st_creator</span></span><a class="headerlink" href="#os.stat_result.st_creator" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Creator of the file.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_type">
|
||
<span class="sig-name descname"><span class="pre">st_type</span></span><a class="headerlink" href="#os.stat_result.st_type" title="Link to this definition">¶</a></dt>
|
||
<dd><p>File type.</p>
|
||
</dd></dl>
|
||
|
||
<p>On Windows systems, the following attributes are also available:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_file_attributes">
|
||
<span class="sig-name descname"><span class="pre">st_file_attributes</span></span><a class="headerlink" href="#os.stat_result.st_file_attributes" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Windows file attributes: <code class="docutils literal notranslate"><span class="pre">dwFileAttributes</span></code> member of the
|
||
<code class="docutils literal notranslate"><span class="pre">BY_HANDLE_FILE_INFORMATION</span></code> structure returned by
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">GetFileInformationByHandle()</span></code>.
|
||
See the <code class="xref py py-const docutils literal notranslate"><span class="pre">FILE_ATTRIBUTE_*</span> <span class="pre"><stat.FILE_ATTRIBUTE_ARCHIVE></span></code>
|
||
constants in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.5.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.stat_result.st_reparse_tag">
|
||
<span class="sig-name descname"><span class="pre">st_reparse_tag</span></span><a class="headerlink" href="#os.stat_result.st_reparse_tag" title="Link to this definition">¶</a></dt>
|
||
<dd><p>When <a class="reference internal" href="#os.stat_result.st_file_attributes" title="os.stat_result.st_file_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_file_attributes</span></code></a> has the <a class="reference internal" href="stat.html#stat.FILE_ATTRIBUTE_REPARSE_POINT" title="stat.FILE_ATTRIBUTE_REPARSE_POINT"><code class="xref py py-const docutils literal notranslate"><span class="pre">FILE_ATTRIBUTE_REPARSE_POINT</span></code></a>
|
||
set, this field contains the tag identifying the type of reparse point.
|
||
See the <a class="reference internal" href="stat.html#stat.IO_REPARSE_TAG_SYMLINK" title="stat.IO_REPARSE_TAG_SYMLINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">IO_REPARSE_TAG_*</span></code></a>
|
||
constants in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module.</p>
|
||
</dd></dl>
|
||
|
||
<p>The standard module <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> defines functions and constants that are
|
||
useful for extracting information from a <code class="xref c c-struct docutils literal notranslate"><span class="pre">stat</span></code> structure. (On
|
||
Windows, some items are filled with dummy values.)</p>
|
||
<p>For backward compatibility, a <a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a> instance is also
|
||
accessible as a tuple of at least 10 integers giving the most important (and
|
||
portable) members of the <code class="xref c c-struct docutils literal notranslate"><span class="pre">stat</span></code> structure, in the order
|
||
<a class="reference internal" href="#os.stat_result.st_mode" title="os.stat_result.st_mode"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mode</span></code></a>, <a class="reference internal" href="#os.stat_result.st_ino" title="os.stat_result.st_ino"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ino</span></code></a>, <a class="reference internal" href="#os.stat_result.st_dev" title="os.stat_result.st_dev"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_dev</span></code></a>, <a class="reference internal" href="#os.stat_result.st_nlink" title="os.stat_result.st_nlink"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_nlink</span></code></a>,
|
||
<a class="reference internal" href="#os.stat_result.st_uid" title="os.stat_result.st_uid"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_uid</span></code></a>, <a class="reference internal" href="#os.stat_result.st_gid" title="os.stat_result.st_gid"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_gid</span></code></a>, <a class="reference internal" href="#os.stat_result.st_size" title="os.stat_result.st_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_size</span></code></a>, <a class="reference internal" href="#os.stat_result.st_atime" title="os.stat_result.st_atime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_atime</span></code></a>,
|
||
<a class="reference internal" href="#os.stat_result.st_mtime" title="os.stat_result.st_mtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mtime</span></code></a>, <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime</span></code></a>. More items may be added at the end by
|
||
some implementations. For compatibility with older Python versions,
|
||
accessing <a class="reference internal" href="#os.stat_result" title="os.stat_result"><code class="xref py py-class docutils literal notranslate"><span class="pre">stat_result</span></code></a> as a tuple always returns integers.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>Windows now returns the file index as <a class="reference internal" href="#os.stat_result.st_ino" title="os.stat_result.st_ino"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ino</span></code></a> when
|
||
available.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <a class="reference internal" href="#os.stat_result.st_fstype" title="os.stat_result.st_fstype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_fstype</span></code></a> member to Solaris/derivatives.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>Added the <a class="reference internal" href="#os.stat_result.st_reparse_tag" title="os.stat_result.st_reparse_tag"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_reparse_tag</span></code></a> member on Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>On Windows, the <a class="reference internal" href="#os.stat_result.st_mode" title="os.stat_result.st_mode"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_mode</span></code></a> member now identifies special
|
||
files as <code class="xref py py-const docutils literal notranslate"><span class="pre">S_IFCHR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">S_IFIFO</span></code> or <code class="xref py py-const docutils literal notranslate"><span class="pre">S_IFBLK</span></code>
|
||
as appropriate.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>On Windows, <a class="reference internal" href="#os.stat_result.st_ctime" title="os.stat_result.st_ctime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ctime</span></code></a> is deprecated. Eventually, it will
|
||
contain the last metadata change time, for consistency with other
|
||
platforms, but for now still contains creation time.
|
||
Use <a class="reference internal" href="#os.stat_result.st_birthtime" title="os.stat_result.st_birthtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime</span></code></a> for the creation time.</p>
|
||
<p>On Windows, <a class="reference internal" href="#os.stat_result.st_ino" title="os.stat_result.st_ino"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_ino</span></code></a> may now be up to 128 bits, depending
|
||
on the file system. Previously it would not be above 64 bits, and
|
||
larger file identifiers would be arbitrarily packed.</p>
|
||
<p>On Windows, <a class="reference internal" href="#os.stat_result.st_rdev" title="os.stat_result.st_rdev"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_rdev</span></code></a> no longer returns a value. Previously
|
||
it would contain the same as <a class="reference internal" href="#os.stat_result.st_dev" title="os.stat_result.st_dev"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_dev</span></code></a>, which was incorrect.</p>
|
||
<p>Added the <a class="reference internal" href="#os.stat_result.st_birthtime" title="os.stat_result.st_birthtime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_birthtime</span></code></a> member on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.statvfs">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">statvfs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.statvfs" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Perform a <code class="xref c c-func docutils literal notranslate"><span class="pre">statvfs()</span></code> system call on the given path. The return value is
|
||
an object whose attributes describe the filesystem on the given path, and
|
||
correspond to the members of the <code class="xref c c-struct docutils literal notranslate"><span class="pre">statvfs</span></code> structure, namely:
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">f_bsize</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_frsize</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_blocks</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_bfree</span></code>,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">f_bavail</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_files</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_ffree</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_favail</span></code>,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">f_flag</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_namemax</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_fsid</span></code>.</p>
|
||
<p>Two module-level constants are defined for the <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_flag</span></code> attribute’s
|
||
bit-flags: if <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_RDONLY</span></code> is set, the filesystem is mounted
|
||
read-only, and if <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOSUID</span></code> is set, the semantics of
|
||
setuid/setgid bits are disabled or not supported.</p>
|
||
<p>Additional module-level constants are defined for GNU/glibc based systems.
|
||
These are <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NODEV</span></code> (disallow access to device special files),
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOEXEC</span></code> (disallow program execution), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_SYNCHRONOUS</span></code>
|
||
(writes are synced at once), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_MANDLOCK</span></code> (allow mandatory locks on an FS),
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">ST_WRITE</span></code> (write on file/directory/symlink), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_APPEND</span></code>
|
||
(append-only file), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_IMMUTABLE</span></code> (immutable file), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOATIME</span></code>
|
||
(do not update access times), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NODIRATIME</span></code> (do not update directory access
|
||
times), <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_RELATIME</span></code> (update atime relative to mtime/ctime).</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>The <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_RDONLY</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOSUID</span></code> constants were added.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.4: </span>The <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NODEV</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOEXEC</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_SYNCHRONOUS</span></code>,
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">ST_MANDLOCK</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_WRITE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_APPEND</span></code>,
|
||
<code class="xref py py-const docutils literal notranslate"><span class="pre">ST_IMMUTABLE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NOATIME</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_NODIRATIME</span></code>,
|
||
and <code class="xref py py-const docutils literal notranslate"><span class="pre">ST_RELATIME</span></code> constants were added.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_fsid</span></code> attribute.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.supports_dir_fd">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">supports_dir_fd</span></span><a class="headerlink" href="#os.supports_dir_fd" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a> object indicating which functions in the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>
|
||
module accept an open file descriptor for their <em>dir_fd</em> parameter.
|
||
Different platforms provide different features, and the underlying
|
||
functionality Python uses to implement the <em>dir_fd</em> parameter is not
|
||
available on all platforms Python supports. For consistency’s sake,
|
||
functions that may support <em>dir_fd</em> always allow specifying the
|
||
parameter, but will throw an exception if the functionality is used
|
||
when it’s not locally available. (Specifying <code class="docutils literal notranslate"><span class="pre">None</span></code> for <em>dir_fd</em>
|
||
is always supported on all platforms.)</p>
|
||
<p>To check whether a particular function accepts an open file descriptor
|
||
for its <em>dir_fd</em> parameter, use the <code class="docutils literal notranslate"><span class="pre">in</span></code> operator on <code class="docutils literal notranslate"><span class="pre">supports_dir_fd</span></code>.
|
||
As an example, this expression evaluates to <code class="docutils literal notranslate"><span class="pre">True</span></code> if <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>
|
||
accepts open file descriptors for <em>dir_fd</em> on the local platform:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">stat</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_dir_fd</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Currently <em>dir_fd</em> parameters only work on Unix platforms;
|
||
none of them work on Windows.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.supports_effective_ids">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">supports_effective_ids</span></span><a class="headerlink" href="#os.supports_effective_ids" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a> object indicating whether <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.access()</span></code></a> permits
|
||
specifying <code class="docutils literal notranslate"><span class="pre">True</span></code> for its <em>effective_ids</em> parameter on the local platform.
|
||
(Specifying <code class="docutils literal notranslate"><span class="pre">False</span></code> for <em>effective_ids</em> is always supported on all
|
||
platforms.) If the local platform supports it, the collection will contain
|
||
<a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.access()</span></code></a>; otherwise it will be empty.</p>
|
||
<p>This expression evaluates to <code class="docutils literal notranslate"><span class="pre">True</span></code> if <a class="reference internal" href="#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.access()</span></code></a> supports
|
||
<code class="docutils literal notranslate"><span class="pre">effective_ids=True</span></code> on the local platform:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">access</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_effective_ids</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Currently <em>effective_ids</em> is only supported on Unix platforms;
|
||
it does not work on Windows.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.supports_fd">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">supports_fd</span></span><a class="headerlink" href="#os.supports_fd" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a> object indicating which functions in the
|
||
<a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module permit specifying their <em>path</em> parameter as an open file
|
||
descriptor on the local platform. Different platforms provide different
|
||
features, and the underlying functionality Python uses to accept open file
|
||
descriptors as <em>path</em> arguments is not available on all platforms Python
|
||
supports.</p>
|
||
<p>To determine whether a particular function permits specifying an open file
|
||
descriptor for its <em>path</em> parameter, use the <code class="docutils literal notranslate"><span class="pre">in</span></code> operator on
|
||
<code class="docutils literal notranslate"><span class="pre">supports_fd</span></code>. As an example, this expression evaluates to <code class="docutils literal notranslate"><span class="pre">True</span></code> if
|
||
<a class="reference internal" href="#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chdir()</span></code></a> accepts open file descriptors for <em>path</em> on your local
|
||
platform:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">chdir</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_fd</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.supports_follow_symlinks">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">supports_follow_symlinks</span></span><a class="headerlink" href="#os.supports_follow_symlinks" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A <a class="reference internal" href="stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a> object indicating which functions in the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module
|
||
accept <code class="docutils literal notranslate"><span class="pre">False</span></code> for their <em>follow_symlinks</em> parameter on the local platform.
|
||
Different platforms provide different features, and the underlying
|
||
functionality Python uses to implement <em>follow_symlinks</em> is not available
|
||
on all platforms Python supports. For consistency’s sake, functions that
|
||
may support <em>follow_symlinks</em> always allow specifying the parameter, but
|
||
will throw an exception if the functionality is used when it’s not locally
|
||
available. (Specifying <code class="docutils literal notranslate"><span class="pre">True</span></code> for <em>follow_symlinks</em> is always supported
|
||
on all platforms.)</p>
|
||
<p>To check whether a particular function accepts <code class="docutils literal notranslate"><span class="pre">False</span></code> for its
|
||
<em>follow_symlinks</em> parameter, use the <code class="docutils literal notranslate"><span class="pre">in</span></code> operator on
|
||
<code class="docutils literal notranslate"><span class="pre">supports_follow_symlinks</span></code>. As an example, this expression evaluates
|
||
to <code class="docutils literal notranslate"><span class="pre">True</span></code> if you may specify <code class="docutils literal notranslate"><span class="pre">follow_symlinks=False</span></code> when calling
|
||
<a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> on the local platform:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">os</span><span class="o">.</span><span class="n">stat</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">supports_follow_symlinks</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.symlink">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">symlink</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">src</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dst</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target_is_directory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.symlink" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create a symbolic link pointing to <em>src</em> named <em>dst</em>.</p>
|
||
<p>On Windows, a symlink represents either a file or a directory, and does not
|
||
morph to the target dynamically. If the target is present, the type of the
|
||
symlink will be created to match. Otherwise, the symlink will be created
|
||
as a directory if <em>target_is_directory</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> or a file symlink (the
|
||
default) otherwise. On non-Windows platforms, <em>target_is_directory</em> is ignored.</p>
|
||
<p>This function can support <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>On newer versions of Windows 10, unprivileged accounts can create symlinks
|
||
if Developer Mode is enabled. When Developer Mode is not available/enabled,
|
||
the <em>SeCreateSymbolicLinkPrivilege</em> privilege is required, or the process
|
||
must be run as an administrator.</p>
|
||
<p><a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised when the function is called by an unprivileged
|
||
user.</p>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.symlink</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">src</span></code>, <code class="docutils literal notranslate"><span class="pre">dst</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
<p>The function is limited on WASI, see <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more
|
||
information.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added support for Windows 6.0 (Vista) symbolic links.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter, and now allow <em>target_is_directory</em>
|
||
on non-Windows platforms.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>src</em> and <em>dst</em>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>Added support for unelevated symlinks on Windows with Developer Mode.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sync">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sync</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.sync" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Force write of everything to disk.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.truncate">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">truncate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.truncate" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Truncate the file corresponding to <em>path</em>, so that it is at most
|
||
<em>length</em> bytes in size.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.truncate</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">length</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>Added support for Windows</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.unlink">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">unlink</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.unlink" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Remove (delete) the file <em>path</em>. This function is semantically
|
||
identical to <a class="reference internal" href="#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">remove()</span></code></a>; the <code class="docutils literal notranslate"><span class="pre">unlink</span></code> name is its
|
||
traditional Unix name. Please see the documentation for
|
||
<a class="reference internal" href="#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">remove()</span></code></a> for further information.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.remove</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>dir_fd</em> parameter.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.utime">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">utime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">times=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*</span></span></em>, <span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">ns</span></span></em>, <span class="optional">]</span><em class="sig-param"><span class="n"><span class="pre">dir_fd=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks=True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.utime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the access and modified times of the file specified by <em>path</em>.</p>
|
||
<p><a class="reference internal" href="#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a> takes two optional parameters, <em>times</em> and <em>ns</em>.
|
||
These specify the times set on <em>path</em> and are used as follows:</p>
|
||
<ul class="simple">
|
||
<li><p>If <em>ns</em> is specified,
|
||
it must be a 2-tuple of the form <code class="docutils literal notranslate"><span class="pre">(atime_ns,</span> <span class="pre">mtime_ns)</span></code>
|
||
where each member is an int expressing nanoseconds.</p></li>
|
||
<li><p>If <em>times</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>,
|
||
it must be a 2-tuple of the form <code class="docutils literal notranslate"><span class="pre">(atime,</span> <span class="pre">mtime)</span></code>
|
||
where each member is an int or float expressing seconds.</p></li>
|
||
<li><p>If <em>times</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code> and <em>ns</em> is unspecified,
|
||
this is equivalent to specifying <code class="docutils literal notranslate"><span class="pre">ns=(atime_ns,</span> <span class="pre">mtime_ns)</span></code>
|
||
where both times are the current time.</p></li>
|
||
</ul>
|
||
<p>It is an error to specify tuples for both <em>times</em> and <em>ns</em>.</p>
|
||
<p>Note that the exact times you set here may not be returned by a subsequent
|
||
<a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a> call, depending on the resolution with which your operating
|
||
system records access and modification times; see <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a>. The best
|
||
way to preserve exact times is to use the <em>st_atime_ns</em> and <em>st_mtime_ns</em>
|
||
fields from the <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> result object with the <em>ns</em> parameter to
|
||
<a class="reference internal" href="#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a>,
|
||
<a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a> and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not
|
||
following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.utime</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">times</span></code>, <code class="docutils literal notranslate"><span class="pre">ns</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor,
|
||
and the <em>dir_fd</em>, <em>follow_symlinks</em>, and <em>ns</em> parameters.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.walk">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">walk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">top</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">topdown</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">onerror</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">followlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.walk" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-31">Generate the file names in a directory tree by walking the tree
|
||
either top-down or bottom-up. For each directory in the tree rooted at directory
|
||
<em>top</em> (including <em>top</em> itself), it yields a 3-tuple <code class="docutils literal notranslate"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span>
|
||
<span class="pre">filenames)</span></code>.</p>
|
||
<p><em>dirpath</em> is a string, the path to the directory. <em>dirnames</em> is a list of the
|
||
names of the subdirectories in <em>dirpath</em> (including symlinks to directories,
|
||
and excluding <code class="docutils literal notranslate"><span class="pre">'.'</span></code> and <code class="docutils literal notranslate"><span class="pre">'..'</span></code>).
|
||
<em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>.
|
||
Note that the names in the lists contain no path components. To get a full path
|
||
(which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do
|
||
<code class="docutils literal notranslate"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></code>. Whether or not the lists are sorted
|
||
depends on the file system. If a file is removed from or added to the
|
||
<em>dirpath</em> directory during generating the lists, whether a name for that
|
||
file be included is unspecified.</p>
|
||
<p>If optional argument <em>topdown</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> or not specified, the triple for a
|
||
directory is generated before the triples for any of its subdirectories
|
||
(directories are generated top-down). If <em>topdown</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the triple
|
||
for a directory is generated after the triples for all of its subdirectories
|
||
(directories are generated bottom-up). No matter the value of <em>topdown</em>, the
|
||
list of subdirectories is retrieved before the tuples for the directory and
|
||
its subdirectories are generated.</p>
|
||
<p>When <em>topdown</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the caller can modify the <em>dirnames</em> list in-place
|
||
(perhaps using <a class="reference internal" href="../reference/simple_stmts.html#del"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">del</span></code></a> or slice assignment), and <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> will only
|
||
recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be
|
||
used to prune the search, impose a specific order of visiting, or even to inform
|
||
<a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> about directories the caller creates or renames before it resumes
|
||
<a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> again. Modifying <em>dirnames</em> when <em>topdown</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> has
|
||
no effect on the behavior of the walk, because in bottom-up mode the directories
|
||
in <em>dirnames</em> are generated before <em>dirpath</em> itself is generated.</p>
|
||
<p>By default, errors from the <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> call are ignored. If optional
|
||
argument <em>onerror</em> is specified, it should be a function; it will be called with
|
||
one argument, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> instance. It can report the error to continue
|
||
with the walk, or raise the exception to abort the walk. Note that the filename
|
||
is available as the <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute of the exception object.</p>
|
||
<p>By default, <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> will not walk down into symbolic links that resolve to
|
||
directories. Set <em>followlinks</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code> to visit directories pointed to by
|
||
symlinks, on systems that support them.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Be aware that setting <em>followlinks</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code> can lead to infinite
|
||
recursion if a link points to a parent directory of itself. <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a>
|
||
does not keep track of the directories it visited already.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>If you pass a relative pathname, don’t change the current working directory
|
||
between resumptions of <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a>. <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> never changes the current
|
||
directory, and assumes that its caller doesn’t either.</p>
|
||
</div>
|
||
<p>This example displays the number of bytes taken by non-directory files in each
|
||
directory under the starting directory, except that it doesn’t look under any
|
||
<code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> subdirectory:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="kn">from</span><span class="w"> </span><span class="nn">os.path</span><span class="w"> </span><span class="kn">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span>
|
||
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s1">'python/Lib/xml'</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s2">"consumes"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">),</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"bytes in"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s2">"non-directory files"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="s1">'__pycache__'</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
|
||
<span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">'__pycache__'</span><span class="p">)</span> <span class="c1"># don't visit __pycache__ directories</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>In the next example (simple implementation of <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a>),
|
||
walking the tree bottom-up is essential, <a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a> doesn’t allow
|
||
deleting a directory before the directory is empty:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Delete everything reachable from the directory named in "top",</span>
|
||
<span class="c1"># assuming there are no symbolic links.</span>
|
||
<span class="c1"># CAUTION: This is dangerous! For example, if top == '/', it</span>
|
||
<span class="c1"># could delete all your disk files.</span>
|
||
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
|
||
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">top</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.walk</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">top</span></code>, <code class="docutils literal notranslate"><span class="pre">topdown</span></code>, <code class="docutils literal notranslate"><span class="pre">onerror</span></code>, <code class="docutils literal notranslate"><span class="pre">followlinks</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>This function now calls <a class="reference internal" href="#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a> instead of <a class="reference internal" href="#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a>,
|
||
making it faster by reducing the number of calls to <a class="reference internal" href="#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fwalk">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fwalk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">top</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'.'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">topdown</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">onerror</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir_fd</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.fwalk" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-32">This behaves exactly like <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a>, except that it yields a 4-tuple
|
||
<code class="docutils literal notranslate"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span> <span class="pre">filenames,</span> <span class="pre">dirfd)</span></code>, and it supports <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<p><em>dirpath</em>, <em>dirnames</em> and <em>filenames</em> are identical to <a class="reference internal" href="#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> output,
|
||
and <em>dirfd</em> is a file descriptor referring to the directory <em>dirpath</em>.</p>
|
||
<p>This function always supports <a class="reference internal" href="#dir-fd"><span class="std std-ref">paths relative to directory descriptors</span></a> and <a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>. Note however
|
||
that, unlike other functions, the <a class="reference internal" href="#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">fwalk()</span></code></a> default value for
|
||
<em>follow_symlinks</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Since <a class="reference internal" href="#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">fwalk()</span></code></a> yields file descriptors, those are only valid until
|
||
the next iteration step, so you should duplicate them (e.g. with
|
||
<a class="reference internal" href="#os.dup" title="os.dup"><code class="xref py py-func docutils literal notranslate"><span class="pre">dup()</span></code></a>) if you want to keep them longer.</p>
|
||
</div>
|
||
<p>This example displays the number of bytes taken by non-directory files in each
|
||
directory under the starting directory, except that it doesn’t look under any
|
||
<code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> subdirectory:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">rootfd</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">fwalk</span><span class="p">(</span><span class="s1">'python/Lib/xml'</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s2">"consumes"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">]),</span>
|
||
<span class="n">end</span><span class="o">=</span><span class="s2">""</span><span class="p">)</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="s2">"bytes in"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s2">"non-directory files"</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="s1">'__pycache__'</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
|
||
<span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">'__pycache__'</span><span class="p">)</span> <span class="c1"># don't visit __pycache__ directories</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>In the next example, walking the tree bottom-up is essential:
|
||
<a class="reference internal" href="#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a> doesn’t allow deleting a directory before the directory is
|
||
empty:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Delete everything reachable from the directory named in "top",</span>
|
||
<span class="c1"># assuming there are no symbolic links.</span>
|
||
<span class="c1"># CAUTION: This is dangerous! For example, if top == '/', it</span>
|
||
<span class="c1"># could delete all your disk files.</span>
|
||
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span><span class="p">,</span> <span class="n">rootfd</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">fwalk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span>
|
||
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dir_fd</span><span class="o">=</span><span class="n">rootfd</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.fwalk</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">top</span></code>, <code class="docutils literal notranslate"><span class="pre">topdown</span></code>, <code class="docutils literal notranslate"><span class="pre">onerror</span></code>, <code class="docutils literal notranslate"><span class="pre">follow_symlinks</span></code>, <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.7: </span>Added support for <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> paths.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.memfd_create">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">memfd_create</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">flags=os.MFD_CLOEXEC</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.memfd_create" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create an anonymous file and return a file descriptor that refers to it.
|
||
<em>flags</em> must be one of the <code class="docutils literal notranslate"><span class="pre">os.MFD_*</span></code> constants available on the system
|
||
(or a bitwise ORed combination of them). By default, the new file
|
||
descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
|
||
<p>The name supplied in <em>name</em> is used as a filename and will be displayed as
|
||
the target of the corresponding symbolic link in the directory
|
||
<code class="docutils literal notranslate"><span class="pre">/proc/self/fd/</span></code>. The displayed name is always prefixed with <code class="docutils literal notranslate"><span class="pre">memfd:</span></code>
|
||
and serves only for debugging purposes. Names do not affect the behavior of
|
||
the file descriptor, and as such multiple files can have the same name
|
||
without any side effects.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 3.17 with glibc >= 2.27.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.MFD_CLOEXEC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_CLOEXEC</span></span><a class="headerlink" href="#os.MFD_CLOEXEC" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_ALLOW_SEALING">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_ALLOW_SEALING</span></span><a class="headerlink" href="#os.MFD_ALLOW_SEALING" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGETLB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGETLB</span></span><a class="headerlink" href="#os.MFD_HUGETLB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_SHIFT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_SHIFT</span></span><a class="headerlink" href="#os.MFD_HUGE_SHIFT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_MASK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_MASK</span></span><a class="headerlink" href="#os.MFD_HUGE_MASK" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_64KB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_64KB</span></span><a class="headerlink" href="#os.MFD_HUGE_64KB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_512KB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_512KB</span></span><a class="headerlink" href="#os.MFD_HUGE_512KB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_1MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_1MB</span></span><a class="headerlink" href="#os.MFD_HUGE_1MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_2MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_2MB</span></span><a class="headerlink" href="#os.MFD_HUGE_2MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_8MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_8MB</span></span><a class="headerlink" href="#os.MFD_HUGE_8MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_16MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_16MB</span></span><a class="headerlink" href="#os.MFD_HUGE_16MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_32MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_32MB</span></span><a class="headerlink" href="#os.MFD_HUGE_32MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_256MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_256MB</span></span><a class="headerlink" href="#os.MFD_HUGE_256MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_512MB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_512MB</span></span><a class="headerlink" href="#os.MFD_HUGE_512MB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_1GB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_1GB</span></span><a class="headerlink" href="#os.MFD_HUGE_1GB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_2GB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_2GB</span></span><a class="headerlink" href="#os.MFD_HUGE_2GB" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.MFD_HUGE_16GB">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">MFD_HUGE_16GB</span></span><a class="headerlink" href="#os.MFD_HUGE_16GB" title="Link to this definition">¶</a></dt>
|
||
<dd><p>These flags can be passed to <a class="reference internal" href="#os.memfd_create" title="os.memfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">memfd_create()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 3.17 with glibc >= 2.27</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">MFD_HUGE*</span></code> flags are only available since Linux 4.14.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.eventfd">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">eventfd</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">initval</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">flags=os.EFD_CLOEXEC</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.eventfd" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create and return an event file descriptor. The file descriptors supports
|
||
raw <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> and <a class="reference internal" href="#os.write" title="os.write"><code class="xref py py-func docutils literal notranslate"><span class="pre">write()</span></code></a> with a buffer size of 8,
|
||
<a class="reference internal" href="select.html#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a>, <a class="reference internal" href="select.html#select.poll" title="select.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">poll()</span></code></a> and similar. See man page
|
||
<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/eventfd(2)">eventfd(2)</a></em> for more information. By default, the
|
||
new file descriptor is <a class="reference internal" href="#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>.</p>
|
||
<p><em>initval</em> is the initial value of the event counter. The initial value
|
||
must be a 32 bit unsigned integer. Please note that the initial value is
|
||
limited to a 32 bit unsigned int although the event counter is an unsigned
|
||
64 bit integer with a maximum value of 2<sup>64</sup>-2.</p>
|
||
<p><em>flags</em> can be constructed from <a class="reference internal" href="#os.EFD_CLOEXEC" title="os.EFD_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_CLOEXEC</span></code></a>,
|
||
<a class="reference internal" href="#os.EFD_NONBLOCK" title="os.EFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_NONBLOCK</span></code></a>, and <a class="reference internal" href="#os.EFD_SEMAPHORE" title="os.EFD_SEMAPHORE"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_SEMAPHORE</span></code></a>.</p>
|
||
<p>If <a class="reference internal" href="#os.EFD_SEMAPHORE" title="os.EFD_SEMAPHORE"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_SEMAPHORE</span></code></a> is specified and the event counter is non-zero,
|
||
<a class="reference internal" href="#os.eventfd_read" title="os.eventfd_read"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd_read()</span></code></a> returns 1 and decrements the counter by one.</p>
|
||
<p>If <a class="reference internal" href="#os.EFD_SEMAPHORE" title="os.EFD_SEMAPHORE"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_SEMAPHORE</span></code></a> is not specified and the event counter is
|
||
non-zero, <a class="reference internal" href="#os.eventfd_read" title="os.eventfd_read"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd_read()</span></code></a> returns the current event counter value and
|
||
resets the counter to zero.</p>
|
||
<p>If the event counter is zero and <a class="reference internal" href="#os.EFD_NONBLOCK" title="os.EFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">EFD_NONBLOCK</span></code></a> is not
|
||
specified, <a class="reference internal" href="#os.eventfd_read" title="os.eventfd_read"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd_read()</span></code></a> blocks.</p>
|
||
<p><a class="reference internal" href="#os.eventfd_write" title="os.eventfd_write"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd_write()</span></code></a> increments the event counter. Write blocks if the
|
||
write operation would increment the counter to a value larger than
|
||
2<sup>64</sup>-2.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
|
||
<span class="c1"># semaphore with start value '1'</span>
|
||
<span class="n">fd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">eventfd</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">EFD_SEMAPHORE</span> <span class="o">|</span> <span class="n">os</span><span class="o">.</span><span class="n">EFC_CLOEXEC</span><span class="p">)</span>
|
||
<span class="k">try</span><span class="p">:</span>
|
||
<span class="c1"># acquire semaphore</span>
|
||
<span class="n">v</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">eventfd_read</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
|
||
<span class="k">try</span><span class="p">:</span>
|
||
<span class="n">do_work</span><span class="p">()</span>
|
||
<span class="k">finally</span><span class="p">:</span>
|
||
<span class="c1"># release semaphore</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">eventfd_write</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
|
||
<span class="k">finally</span><span class="p">:</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.eventfd_read">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">eventfd_read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.eventfd_read" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Read value from an <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a> file descriptor and return a 64 bit
|
||
unsigned int. The function does not verify that <em>fd</em> is an <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.eventfd_write">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">eventfd_write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.eventfd_write" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Add value to an <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a> file descriptor. <em>value</em> must be a 64 bit
|
||
unsigned int. The function does not verify that <em>fd</em> is an <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EFD_CLOEXEC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EFD_CLOEXEC</span></span><a class="headerlink" href="#os.EFD_CLOEXEC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set close-on-exec flag for new <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a> file descriptor.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EFD_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EFD_NONBLOCK</span></span><a class="headerlink" href="#os.EFD_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set <a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> status flag for new <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a> file
|
||
descriptor.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EFD_SEMAPHORE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EFD_SEMAPHORE</span></span><a class="headerlink" href="#os.EFD_SEMAPHORE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Provide semaphore-like semantics for reads from an <a class="reference internal" href="#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">eventfd()</span></code></a> file
|
||
descriptor. On read the internal counter is decremented by one.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.30</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.10.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<section id="timer-file-descriptors">
|
||
<span id="os-timerfd"></span><h3>Timer File Descriptors<a class="headerlink" href="#timer-file-descriptors" title="Link to this heading">¶</a></h3>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
<p>These functions provide support for Linux’s <em>timer file descriptor</em> API.
|
||
Naturally, they are all only available on Linux.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.timerfd_create">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">timerfd_create</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clockid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.timerfd_create" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Create and return a timer file descriptor (<em>timerfd</em>).</p>
|
||
<p>The file descriptor returned by <a class="reference internal" href="#os.timerfd_create" title="os.timerfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_create()</span></code></a> supports:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="select.html#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="select.html#select.poll" title="select.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">poll()</span></code></a></p></li>
|
||
</ul>
|
||
<p>The file descriptor’s <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> method can be called with a buffer size
|
||
of 8. If the timer has already expired one or more times, <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a>
|
||
returns the number of expirations with the host’s endianness, which may be
|
||
converted to an <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> by <code class="docutils literal notranslate"><span class="pre">int.from_bytes(x,</span> <span class="pre">byteorder=sys.byteorder)</span></code>.</p>
|
||
<p><a class="reference internal" href="select.html#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a> and <a class="reference internal" href="select.html#select.poll" title="select.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">poll()</span></code></a> can be used to wait until
|
||
timer expires and the file descriptor is readable.</p>
|
||
<p><em>clockid</em> must be a valid <a class="reference internal" href="time.html#time-clock-id-constants"><span class="std std-ref">clock ID</span></a>,
|
||
as defined in the <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="time.html#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_REALTIME</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="time.html#time.CLOCK_BOOTTIME" title="time.CLOCK_BOOTTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_BOOTTIME</span></code></a> (Since Linux 3.15 for timerfd_create)</p></li>
|
||
</ul>
|
||
<p>If <em>clockid</em> is <a class="reference internal" href="time.html#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_REALTIME</span></code></a>, a settable system-wide
|
||
real-time clock is used. If system clock is changed, timer setting need
|
||
to be updated. To cancel timer when system clock is changed, see
|
||
<a class="reference internal" href="#os.TFD_TIMER_CANCEL_ON_SET" title="os.TFD_TIMER_CANCEL_ON_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_CANCEL_ON_SET</span></code></a>.</p>
|
||
<p>If <em>clockid</em> is <a class="reference internal" href="time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a>, a non-settable monotonically
|
||
increasing clock is used. Even if the system clock is changed, the timer
|
||
setting will not be affected.</p>
|
||
<p>If <em>clockid</em> is <a class="reference internal" href="time.html#time.CLOCK_BOOTTIME" title="time.CLOCK_BOOTTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_BOOTTIME</span></code></a>, same as <a class="reference internal" href="time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a>
|
||
except it includes any time that the system is suspended.</p>
|
||
<p>The file descriptor’s behaviour can be modified by specifying a <em>flags</em> value.
|
||
Any of the following variables may used, combined using bitwise OR
|
||
(the <code class="docutils literal notranslate"><span class="pre">|</span></code> operator):</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.TFD_NONBLOCK" title="os.TFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_NONBLOCK</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="#os.TFD_CLOEXEC" title="os.TFD_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_CLOEXEC</span></code></a></p></li>
|
||
</ul>
|
||
<p>If <a class="reference internal" href="#os.TFD_NONBLOCK" title="os.TFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_NONBLOCK</span></code></a> is not set as a flag, <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> blocks until
|
||
the timer expires. If it is set as a flag, <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> doesn’t block, but
|
||
If there hasn’t been an expiration since the last call to read,
|
||
<a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-class docutils literal notranslate"><span class="pre">OSError</span></code></a> with <code class="docutils literal notranslate"><span class="pre">errno</span></code> is set to
|
||
<a class="reference internal" href="errno.html#errno.EAGAIN" title="errno.EAGAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EAGAIN</span></code></a>.</p>
|
||
<p><a class="reference internal" href="#os.TFD_CLOEXEC" title="os.TFD_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_CLOEXEC</span></code></a> is always set by Python automatically.</p>
|
||
<p>The file descriptor must be closed with <a class="reference internal" href="#os.close" title="os.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.close()</span></code></a> when it is no
|
||
longer needed, or else the file descriptor will be leaked.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/timerfd_create(2)">timerfd_create(2)</a></em> man page.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.timerfd_settime">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">timerfd_settime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">flags</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">initial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.timerfd_settime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Alter a timer file descriptor’s internal timer.
|
||
This function operates the same interval timer as <a class="reference internal" href="#os.timerfd_settime_ns" title="os.timerfd_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime_ns()</span></code></a>.</p>
|
||
<p><em>fd</em> must be a valid timer file descriptor.</p>
|
||
<p>The timer’s behaviour can be modified by specifying a <em>flags</em> value.
|
||
Any of the following variables may used, combined using bitwise OR
|
||
(the <code class="docutils literal notranslate"><span class="pre">|</span></code> operator):</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="#os.TFD_TIMER_CANCEL_ON_SET" title="os.TFD_TIMER_CANCEL_ON_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_CANCEL_ON_SET</span></code></a></p></li>
|
||
</ul>
|
||
<p>The timer is disabled by setting <em>initial</em> to zero (<code class="docutils literal notranslate"><span class="pre">0</span></code>).
|
||
If <em>initial</em> is equal to or greater than zero, the timer is enabled.
|
||
If <em>initial</em> is less than zero, it raises an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-class docutils literal notranslate"><span class="pre">OSError</span></code></a> exception
|
||
with <code class="docutils literal notranslate"><span class="pre">errno</span></code> set to <a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINVAL</span></code></a></p>
|
||
<p>By default the timer will fire when <em>initial</em> seconds have elapsed.
|
||
(If <em>initial</em> is zero, timer will fire immediately.)</p>
|
||
<p>However, if the <a class="reference internal" href="#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a> flag is set,
|
||
the timer will fire when the timer’s clock
|
||
(set by <em>clockid</em> in <a class="reference internal" href="#os.timerfd_create" title="os.timerfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_create()</span></code></a>) reaches <em>initial</em> seconds.</p>
|
||
<p>The timer’s interval is set by the <em>interval</em> <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>.
|
||
If <em>interval</em> is zero, the timer only fires once, on the initial expiration.
|
||
If <em>interval</em> is greater than zero, the timer fires every time <em>interval</em>
|
||
seconds have elapsed since the previous expiration.
|
||
If <em>interval</em> is less than zero, it raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-class docutils literal notranslate"><span class="pre">OSError</span></code></a> with <code class="docutils literal notranslate"><span class="pre">errno</span></code>
|
||
set to <a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINVAL</span></code></a></p>
|
||
<p>If the <a class="reference internal" href="#os.TFD_TIMER_CANCEL_ON_SET" title="os.TFD_TIMER_CANCEL_ON_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_CANCEL_ON_SET</span></code></a> flag is set along with
|
||
<a class="reference internal" href="#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a> and the clock for this timer is
|
||
<a class="reference internal" href="time.html#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_REALTIME</span></code></a>, the timer is marked as cancelable if the
|
||
real-time clock is changed discontinuously. Reading the descriptor is
|
||
aborted with the error ECANCELED.</p>
|
||
<p>Linux manages system clock as UTC. A daylight-savings time transition is
|
||
done by changing time offset only and doesn’t cause discontinuous system
|
||
clock change.</p>
|
||
<p>Discontinuous system clock change will be caused by the following events:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">settimeofday</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">clock_settime</span></code></p></li>
|
||
<li><p>set the system date and time by <code class="docutils literal notranslate"><span class="pre">date</span></code> command</p></li>
|
||
</ul>
|
||
<p>Return a two-item tuple of (<code class="docutils literal notranslate"><span class="pre">next_expiration</span></code>, <code class="docutils literal notranslate"><span class="pre">interval</span></code>) from
|
||
the previous timer state, before this function executed.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/timerfd_create(2)">timerfd_create(2)</a></em>, <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/timerfd_settime(2)">timerfd_settime(2)</a></em>,
|
||
<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/settimeofday(2)">settimeofday(2)</a></em>, <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/clock_settime(2)">clock_settime(2)</a></em>,
|
||
and <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/date(1)">date(1)</a></em>.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.timerfd_settime_ns">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">timerfd_settime_ns</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">initial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.timerfd_settime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Similar to <a class="reference internal" href="#os.timerfd_settime" title="os.timerfd_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime()</span></code></a>, but use time as nanoseconds.
|
||
This function operates the same interval timer as <a class="reference internal" href="#os.timerfd_settime" title="os.timerfd_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.timerfd_gettime">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">timerfd_gettime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.timerfd_gettime" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a two-item tuple of floats (<code class="docutils literal notranslate"><span class="pre">next_expiration</span></code>, <code class="docutils literal notranslate"><span class="pre">interval</span></code>).</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">next_expiration</span></code> denotes the relative time until next the timer next fires,
|
||
regardless of if the <a class="reference internal" href="#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a> flag is set.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">interval</span></code> denotes the timer’s interval.
|
||
If zero, the timer will only fire once, after <code class="docutils literal notranslate"><span class="pre">next_expiration</span></code> seconds
|
||
have elapsed.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/timerfd_gettime(2)">timerfd_gettime(2)</a></em></p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.timerfd_gettime_ns">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">timerfd_gettime_ns</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.timerfd_gettime_ns" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Similar to <a class="reference internal" href="#os.timerfd_gettime" title="os.timerfd_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_gettime()</span></code></a>, but return time as nanoseconds.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.TFD_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">TFD_NONBLOCK</span></span><a class="headerlink" href="#os.TFD_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A flag for the <a class="reference internal" href="#os.timerfd_create" title="os.timerfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_create()</span></code></a> function,
|
||
which sets the <a class="reference internal" href="#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> status flag for the new timer file
|
||
descriptor. If <a class="reference internal" href="#os.TFD_NONBLOCK" title="os.TFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_NONBLOCK</span></code></a> is not set as a flag, <a class="reference internal" href="#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> blocks.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.TFD_CLOEXEC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">TFD_CLOEXEC</span></span><a class="headerlink" href="#os.TFD_CLOEXEC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A flag for the <a class="reference internal" href="#os.timerfd_create" title="os.timerfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_create()</span></code></a> function,
|
||
If <a class="reference internal" href="#os.TFD_CLOEXEC" title="os.TFD_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_CLOEXEC</span></code></a> is set as a flag, set close-on-exec flag for new file
|
||
descriptor.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.TFD_TIMER_ABSTIME">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">TFD_TIMER_ABSTIME</span></span><a class="headerlink" href="#os.TFD_TIMER_ABSTIME" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A flag for the <a class="reference internal" href="#os.timerfd_settime" title="os.timerfd_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime()</span></code></a> and <a class="reference internal" href="#os.timerfd_settime_ns" title="os.timerfd_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime_ns()</span></code></a> functions.
|
||
If this flag is set, <em>initial</em> is interpreted as an absolute value on the
|
||
timer’s clock (in UTC seconds or nanoseconds since the Unix Epoch).</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.TFD_TIMER_CANCEL_ON_SET">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">TFD_TIMER_CANCEL_ON_SET</span></span><a class="headerlink" href="#os.TFD_TIMER_CANCEL_ON_SET" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A flag for the <a class="reference internal" href="#os.timerfd_settime" title="os.timerfd_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime()</span></code></a> and <a class="reference internal" href="#os.timerfd_settime_ns" title="os.timerfd_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime_ns()</span></code></a>
|
||
functions along with <a class="reference internal" href="#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a>.
|
||
The timer is cancelled when the time of the underlying clock changes
|
||
discontinuously.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 2.6.27 with glibc >= 2.8</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="linux-extended-attributes">
|
||
<h3>Linux extended attributes<a class="headerlink" href="#linux-extended-attributes" title="Link to this heading">¶</a></h3>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<p>These functions are all available on Linux only.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getxattr">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getxattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attribute</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getxattr" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the value of the extended filesystem attribute <em>attribute</em> for
|
||
<em>path</em>. <em>attribute</em> can be bytes or str (directly or indirectly through the
|
||
<a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface). If it is str, it is encoded with the filesystem
|
||
encoding.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a> and
|
||
<a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.getxattr</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">attribute</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>path</em> and <em>attribute</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.listxattr">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">listxattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.listxattr" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a list of the extended filesystem attributes on <em>path</em>. The
|
||
attributes in the list are represented as strings decoded with the filesystem
|
||
encoding. If <em>path</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#os.listxattr" title="os.listxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">listxattr()</span></code></a> will examine the current
|
||
directory.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a> and
|
||
<a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.listxattr</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.removexattr">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">removexattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attribute</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.removexattr" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Removes the extended filesystem attribute <em>attribute</em> from <em>path</em>.
|
||
<em>attribute</em> should be bytes or str (directly or indirectly through the
|
||
<a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface). If it is a string, it is encoded
|
||
with the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a> and
|
||
<a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.removexattr</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">attribute</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>path</em> and <em>attribute</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.setxattr">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">setxattr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attribute</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_symlinks</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.setxattr" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the extended filesystem attribute <em>attribute</em> on <em>path</em> to <em>value</em>.
|
||
<em>attribute</em> must be a bytes or str with no embedded NULs (directly or
|
||
indirectly through the <a class="reference internal" href="#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> interface). If it is a str,
|
||
it is encoded with the <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>. <em>flags</em> may be
|
||
<a class="reference internal" href="#os.XATTR_REPLACE" title="os.XATTR_REPLACE"><code class="xref py py-data docutils literal notranslate"><span class="pre">XATTR_REPLACE</span></code></a> or <a class="reference internal" href="#os.XATTR_CREATE" title="os.XATTR_CREATE"><code class="xref py py-data docutils literal notranslate"><span class="pre">XATTR_CREATE</span></code></a>. If <a class="reference internal" href="#os.XATTR_REPLACE" title="os.XATTR_REPLACE"><code class="xref py py-data docutils literal notranslate"><span class="pre">XATTR_REPLACE</span></code></a> is
|
||
given and the attribute does not exist, <code class="docutils literal notranslate"><span class="pre">ENODATA</span></code> will be raised.
|
||
If <a class="reference internal" href="#os.XATTR_CREATE" title="os.XATTR_CREATE"><code class="xref py py-data docutils literal notranslate"><span class="pre">XATTR_CREATE</span></code></a> is given and the attribute already exists, the
|
||
attribute will not be created and <code class="docutils literal notranslate"><span class="pre">EEXISTS</span></code> will be raised.</p>
|
||
<p>This function can support <a class="reference internal" href="#path-fd"><span class="std std-ref">specifying a file descriptor</span></a> and
|
||
<a class="reference internal" href="#follow-symlinks"><span class="std std-ref">not following symlinks</span></a>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>A bug in Linux kernel versions less than 2.6.39 caused the flags argument
|
||
to be ignored on some filesystems.</p>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.setxattr</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">attribute</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>, <code class="docutils literal notranslate"><span class="pre">flags</span></code>.</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> for <em>path</em> and <em>attribute</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.XATTR_SIZE_MAX">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">XATTR_SIZE_MAX</span></span><a class="headerlink" href="#os.XATTR_SIZE_MAX" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The maximum size the value of an extended attribute can be. Currently, this
|
||
is 64 KiB on Linux.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.XATTR_CREATE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">XATTR_CREATE</span></span><a class="headerlink" href="#os.XATTR_CREATE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This is a possible value for the flags argument in <a class="reference internal" href="#os.setxattr" title="os.setxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setxattr()</span></code></a>. It
|
||
indicates the operation must create an attribute.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.XATTR_REPLACE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">XATTR_REPLACE</span></span><a class="headerlink" href="#os.XATTR_REPLACE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This is a possible value for the flags argument in <a class="reference internal" href="#os.setxattr" title="os.setxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setxattr()</span></code></a>. It
|
||
indicates the operation must replace an existing attribute.</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
</section>
|
||
<section id="process-management">
|
||
<span id="os-process"></span><h2>Process Management<a class="headerlink" href="#process-management" title="Link to this heading">¶</a></h2>
|
||
<p>These functions may be used to create and manage processes.</p>
|
||
<p>The various <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec*</span></code></a> functions take a list of arguments for the new
|
||
program loaded into the process. In each case, the first of these arguments is
|
||
passed to the new program as its own name rather than as an argument a user may
|
||
have typed on a command line. For the C programmer, this is the <code class="docutils literal notranslate"><span class="pre">argv[0]</span></code>
|
||
passed to a program’s <code class="xref c c-func docutils literal notranslate"><span class="pre">main()</span></code>. For example, <code class="docutils literal notranslate"><span class="pre">os.execv('/bin/echo',</span>
|
||
<span class="pre">['foo',</span> <span class="pre">'bar'])</span></code> will only print <code class="docutils literal notranslate"><span class="pre">bar</span></code> on standard output; <code class="docutils literal notranslate"><span class="pre">foo</span></code> will seem
|
||
to be ignored.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.abort">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">abort</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.abort" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Generate a <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGABRT</span></code> signal to the current process. On Unix, the default
|
||
behavior is to produce a core dump; on Windows, the process immediately returns
|
||
an exit code of <code class="docutils literal notranslate"><span class="pre">3</span></code>. Be aware that calling this function will not call the
|
||
Python signal handler registered for <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGABRT</span></code> with
|
||
<a class="reference internal" href="signal.html#signal.signal" title="signal.signal"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.signal()</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.add_dll_directory">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">add_dll_directory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.add_dll_directory" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Add a path to the DLL search path.</p>
|
||
<p>This search path is used when resolving dependencies for imported
|
||
extension modules (the module itself is resolved through
|
||
<a class="reference internal" href="sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>), and also by <a class="reference internal" href="ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>.</p>
|
||
<p>Remove the directory by calling <strong>close()</strong> on the returned object
|
||
or using it in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement.</p>
|
||
<p>See the <a class="reference external" href="https://msdn.microsoft.com/44228cf2-6306-466c-8f16-f513cd3ba8b5">Microsoft documentation</a>
|
||
for more information about how DLLs are loaded.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.add_dll_directory</span></code> with argument <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8: </span>Previous versions of CPython would resolve DLLs using the default
|
||
behavior for the current process. This led to inconsistencies,
|
||
such as only sometimes searching <span class="target" id="index-33"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> or the current
|
||
working directory, and OS functions such as <code class="docutils literal notranslate"><span class="pre">AddDllDirectory</span></code>
|
||
having no effect.</p>
|
||
<p>In 3.8, the two primary ways DLLs are loaded now explicitly
|
||
override the process-wide behavior to ensure consistency. See the
|
||
<a class="reference internal" href="../whatsnew/3.8.html#bpo-36085-whatsnew"><span class="std std-ref">porting notes</span></a> for information on
|
||
updating libraries.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.execl">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execl" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execle">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execle" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execlp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execlp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execlp" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execlpe">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execlpe</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">arg1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execlpe" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execv" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execve">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execve" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execvp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execvp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execvp" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.execvpe">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">execvpe</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.execvpe" title="Link to this definition">¶</a></dt>
|
||
<dd><p>These functions all execute a new program, replacing the current process; they
|
||
do not return. On Unix, the new executable is loaded into the current process,
|
||
and will have the same process id as the caller. Errors will be reported as
|
||
<a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exceptions.</p>
|
||
<p>The current process is replaced immediately. Open file objects and
|
||
descriptors are not flushed, so if there may be data buffered
|
||
on these open files, you should flush them using
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">sys.stdout.flush()</span></code> or <a class="reference internal" href="#os.fsync" title="os.fsync"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsync()</span></code></a> before calling an
|
||
<a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec*</span></code></a> function.</p>
|
||
<p>The “l” and “v” variants of the <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec*</span></code></a> functions differ in how
|
||
command-line arguments are passed. The “l” variants are perhaps the easiest
|
||
to work with if the number of parameters is fixed when the code is written; the
|
||
individual parameters simply become additional parameters to the <code class="xref py py-func docutils literal notranslate"><span class="pre">execl*()</span></code>
|
||
functions. The “v” variants are good when the number of parameters is
|
||
variable, with the arguments being passed in a list or tuple as the <em>args</em>
|
||
parameter. In either case, the arguments to the child process should start with
|
||
the name of the command being run, but this is not enforced.</p>
|
||
<p>The variants which include a “p” near the end (<a class="reference internal" href="#os.execlp" title="os.execlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">execlp()</span></code></a>,
|
||
<a class="reference internal" href="#os.execlpe" title="os.execlpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">execlpe()</span></code></a>, <a class="reference internal" href="#os.execvp" title="os.execvp"><code class="xref py py-func docutils literal notranslate"><span class="pre">execvp()</span></code></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">execvpe()</span></code></a>) will use the
|
||
<span class="target" id="index-34"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to locate the program <em>file</em>. When the
|
||
environment is being replaced (using one of the <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec*e</span></code></a> variants,
|
||
discussed in the next paragraph), the new environment is used as the source of
|
||
the <span class="target" id="index-35"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> variable. The other variants, <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">execl()</span></code></a>, <a class="reference internal" href="#os.execle" title="os.execle"><code class="xref py py-func docutils literal notranslate"><span class="pre">execle()</span></code></a>,
|
||
<a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal notranslate"><span class="pre">execv()</span></code></a>, and <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>, will not use the <span class="target" id="index-36"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> variable to
|
||
locate the executable; <em>path</em> must contain an appropriate absolute or relative
|
||
path. Relative paths must include at least one slash, even on Windows, as
|
||
plain names will not be resolved.</p>
|
||
<p>For <a class="reference internal" href="#os.execle" title="os.execle"><code class="xref py py-func docutils literal notranslate"><span class="pre">execle()</span></code></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">execlpe()</span></code></a>, <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">execvpe()</span></code></a> (note
|
||
that these all end in “e”), the <em>env</em> parameter must be a mapping which is
|
||
used to define the environment variables for the new process (these are used
|
||
instead of the current process’ environment); the functions <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">execl()</span></code></a>,
|
||
<a class="reference internal" href="#os.execlp" title="os.execlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">execlp()</span></code></a>, <a class="reference internal" href="#os.execv" title="os.execv"><code class="xref py py-func docutils literal notranslate"><span class="pre">execv()</span></code></a>, and <a class="reference internal" href="#os.execvp" title="os.execvp"><code class="xref py py-func docutils literal notranslate"><span class="pre">execvp()</span></code></a> all cause the new process to
|
||
inherit the environment of the current process.</p>
|
||
<p>For <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a> on some platforms, <em>path</em> may also be specified as an open
|
||
file descriptor. This functionality may not be supported on your platform;
|
||
you can check whether or not it is available using <a class="reference internal" href="#os.supports_fd" title="os.supports_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_fd</span></code></a>.
|
||
If it is unavailable, using it will raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.exec</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">args</span></code>, <code class="docutils literal notranslate"><span class="pre">env</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Added support for specifying <em>path</em> as an open file descriptor
|
||
for <a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os._exit">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">_exit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os._exit" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit the process with status <em>n</em>, without calling cleanup handlers, flushing
|
||
stdio buffers, etc.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>The standard way to exit is <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit(n)</span></code></a>. <code class="xref py py-func docutils literal notranslate"><span class="pre">_exit()</span></code> should
|
||
normally only be used in the child process after a <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>The following exit codes are defined and can be used with <a class="reference internal" href="#os._exit" title="os._exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">_exit()</span></code></a>,
|
||
although they are not required. These are typically used for system programs
|
||
written in Python, such as a mail server’s external command delivery program.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Some of these may not be available on all Unix platforms, since there is some
|
||
variation. These constants are defined where they are defined by the underlying
|
||
platform.</p>
|
||
</div>
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_OK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_OK</span></span><a class="headerlink" href="#os.EX_OK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means no error occurred. May be taken from the defined value of
|
||
<code class="docutils literal notranslate"><span class="pre">EXIT_SUCCESS</span></code> on some platforms. Generally has a value of zero.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_USAGE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_USAGE</span></span><a class="headerlink" href="#os.EX_USAGE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means the command was used incorrectly, such as when the wrong
|
||
number of arguments are given.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_DATAERR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_DATAERR</span></span><a class="headerlink" href="#os.EX_DATAERR" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means the input data was incorrect.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_NOINPUT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_NOINPUT</span></span><a class="headerlink" href="#os.EX_NOINPUT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means an input file did not exist or was not readable.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_NOUSER">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_NOUSER</span></span><a class="headerlink" href="#os.EX_NOUSER" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means a specified user did not exist.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_NOHOST">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_NOHOST</span></span><a class="headerlink" href="#os.EX_NOHOST" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means a specified host did not exist.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_UNAVAILABLE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_UNAVAILABLE</span></span><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means that a required service is unavailable.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_SOFTWARE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_SOFTWARE</span></span><a class="headerlink" href="#os.EX_SOFTWARE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means an internal software error was detected.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_OSERR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_OSERR</span></span><a class="headerlink" href="#os.EX_OSERR" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means an operating system error was detected, such as the
|
||
inability to fork or create a pipe.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_OSFILE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_OSFILE</span></span><a class="headerlink" href="#os.EX_OSFILE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means some system file did not exist, could not be opened, or had
|
||
some other kind of error.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_CANTCREAT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_CANTCREAT</span></span><a class="headerlink" href="#os.EX_CANTCREAT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means a user specified output file could not be created.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_IOERR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_IOERR</span></span><a class="headerlink" href="#os.EX_IOERR" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means that an error occurred while doing I/O on some file.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_TEMPFAIL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_TEMPFAIL</span></span><a class="headerlink" href="#os.EX_TEMPFAIL" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means a temporary failure occurred. This indicates something
|
||
that may not really be an error, such as a network connection that couldn’t be
|
||
made during a retryable operation.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_PROTOCOL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_PROTOCOL</span></span><a class="headerlink" href="#os.EX_PROTOCOL" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not
|
||
understood.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_NOPERM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_NOPERM</span></span><a class="headerlink" href="#os.EX_NOPERM" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means that there were insufficient permissions to perform the
|
||
operation (but not intended for file system problems).</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_CONFIG">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_CONFIG</span></span><a class="headerlink" href="#os.EX_CONFIG" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means that some kind of configuration error occurred.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.EX_NOTFOUND">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">EX_NOTFOUND</span></span><a class="headerlink" href="#os.EX_NOTFOUND" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Exit code that means something like “an entry was not found”.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.fork">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">fork</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.fork" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Fork a child process. Return <code class="docutils literal notranslate"><span class="pre">0</span></code> in the child and the child’s process id in the
|
||
parent. If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised.</p>
|
||
<p>Note that some platforms including FreeBSD <= 6.3 and Cygwin have
|
||
known issues when using <code class="docutils literal notranslate"><span class="pre">fork()</span></code> from a thread.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.fork</span></code> with no arguments.</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">Warning</p>
|
||
<p>If you use TLS sockets in an application calling <code class="docutils literal notranslate"><span class="pre">fork()</span></code>, see
|
||
the warning in the <a class="reference internal" href="ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> documentation.</p>
|
||
</div>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">Warning</p>
|
||
<p>On macOS the use of this function is unsafe when mixed with using
|
||
higher-level system APIs, and that includes using <a class="reference internal" href="urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>Calling <code class="docutils literal notranslate"><span class="pre">fork()</span></code> in a subinterpreter is no longer supported
|
||
(<a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised).</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>If Python is able to detect that your process has multiple
|
||
threads, <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a> now raises a <a class="reference internal" href="exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>.</p>
|
||
<p>We chose to surface this as a warning, when detectable, to better
|
||
inform developers of a design problem that the POSIX platform
|
||
specifically notes as not supported. Even in code that
|
||
<em>appears</em> to work, it has never been safe to mix threading with
|
||
<a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a> on POSIX platforms. The CPython runtime itself has
|
||
always made API calls that are not safe for use in the child
|
||
process when threads existed in the parent (such as <code class="docutils literal notranslate"><span class="pre">malloc</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">free</span></code>).</p>
|
||
<p>Users of macOS or users of libc or malloc implementations other
|
||
than those typically found in glibc to date are among those
|
||
already more likely to experience deadlocks running such code.</p>
|
||
<p>See <a class="reference external" href="https://discuss.python.org/t/33555">this discussion on fork being incompatible with threads</a>
|
||
for technical details of why we’re surfacing this longstanding
|
||
platform compatibility problem to developers.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: POSIX, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.forkpty">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">forkpty</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.forkpty" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Fork a child process, using a new pseudo-terminal as the child’s controlling
|
||
terminal. Return a pair of <code class="docutils literal notranslate"><span class="pre">(pid,</span> <span class="pre">fd)</span></code>, where <em>pid</em> is <code class="docutils literal notranslate"><span class="pre">0</span></code> in the child, the
|
||
new child’s process id in the parent, and <em>fd</em> is the file descriptor of the
|
||
master end of the pseudo-terminal. For a more portable approach, use the
|
||
<a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Unix. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code></a> module. If an error occurs <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.forkpty</span></code> with no arguments.</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">Warning</p>
|
||
<p>On macOS the use of this function is unsafe when mixed with using
|
||
higher-level system APIs, and that includes using <a class="reference internal" href="urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.8: </span>Calling <code class="docutils literal notranslate"><span class="pre">forkpty()</span></code> in a subinterpreter is no longer supported
|
||
(<a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised).</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.12: </span>If Python is able to detect that your process has multiple
|
||
threads, this now raises a <a class="reference internal" href="exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>. See the
|
||
longer explanation on <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a>.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.kill">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">kill</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sig</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.kill" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-37">Send signal <em>sig</em> to the process <em>pid</em>. Constants for the specific signals
|
||
available on the host platform are defined in the <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module.</p>
|
||
<p>Windows: The <a class="reference internal" href="signal.html#signal.CTRL_C_EVENT" title="signal.CTRL_C_EVENT"><code class="xref py py-const docutils literal notranslate"><span class="pre">signal.CTRL_C_EVENT</span></code></a> and
|
||
<a class="reference internal" href="signal.html#signal.CTRL_BREAK_EVENT" title="signal.CTRL_BREAK_EVENT"><code class="xref py py-const docutils literal notranslate"><span class="pre">signal.CTRL_BREAK_EVENT</span></code></a> signals are special signals which can
|
||
only be sent to console processes which share a common console window,
|
||
e.g., some subprocesses. Any other value for <em>sig</em> will cause the process
|
||
to be unconditionally killed by the TerminateProcess API, and the exit code
|
||
will be set to <em>sig</em>.</p>
|
||
<p>See also <a class="reference internal" href="signal.html#signal.pthread_kill" title="signal.pthread_kill"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.pthread_kill()</span></code></a>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.kill</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">pid</span></code>, <code class="docutils literal notranslate"><span class="pre">sig</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not iOS.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.2: </span>Added Windows support.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.killpg">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">killpg</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pgid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sig</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.killpg" title="Link to this definition">¶</a></dt>
|
||
<dd><p id="index-38">Send the signal <em>sig</em> to the process group <em>pgid</em>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.killpg</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">pgid</span></code>, <code class="docutils literal notranslate"><span class="pre">sig</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.nice">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">nice</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">increment</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.nice" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Add <em>increment</em> to the process’s “niceness”. Return the new niceness.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.pidfd_open">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pidfd_open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.pidfd_open" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a file descriptor referring to the process <em>pid</em> with <em>flags</em> set.
|
||
This descriptor can be used to perform process management without races
|
||
and signals.</p>
|
||
<p>See the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/pidfd_open(2)">pidfd_open(2)</a></em> man page for more details.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 5.3, Android >= <a class="reference internal" href="sys.html#sys.getandroidapilevel" title="sys.getandroidapilevel"><code class="xref py py-func docutils literal notranslate"><span class="pre">build-time</span></code></a> API level 31</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.9.</span></p>
|
||
</div>
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.PIDFD_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">PIDFD_NONBLOCK</span></span><a class="headerlink" href="#os.PIDFD_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This flag indicates that the file descriptor will be non-blocking.
|
||
If the process referred to by the file descriptor has not yet terminated,
|
||
then an attempt to wait on the file descriptor using <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/waitid(2)">waitid(2)</a></em>
|
||
will immediately return the error <a class="reference internal" href="errno.html#errno.EAGAIN" title="errno.EAGAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">EAGAIN</span></code></a> rather than blocking.</p>
|
||
</dd></dl>
|
||
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 5.10</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.12.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.plock">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">plock</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">op</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.plock" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Lock program segments into memory. The value of <em>op</em> (defined in
|
||
<code class="docutils literal notranslate"><span class="pre"><sys/lock.h></span></code>) determines which segments are locked.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.popen">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">popen</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffering</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.popen" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Open a pipe to or from command <em>cmd</em>.
|
||
The return value is an open file object
|
||
connected to the pipe, which can be read or written depending on whether <em>mode</em>
|
||
is <code class="docutils literal notranslate"><span class="pre">'r'</span></code> (default) or <code class="docutils literal notranslate"><span class="pre">'w'</span></code>.
|
||
The <em>buffering</em> argument have the same meaning as
|
||
the corresponding argument to the built-in <a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function. The
|
||
returned file object reads or writes text strings rather than bytes.</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">close</span></code> method returns <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> if the subprocess exited
|
||
successfully, or the subprocess’s return code if there was an
|
||
error. On POSIX systems, if the return code is positive it
|
||
represents the return value of the process left-shifted by one
|
||
byte. If the return code is negative, the process was terminated
|
||
by the signal given by the negated value of the return code. (For
|
||
example, the return value might be <code class="docutils literal notranslate"><span class="pre">-</span> <span class="pre">signal.SIGKILL</span></code> if the
|
||
subprocess was killed.) On Windows systems, the return value
|
||
contains the signed integer return code from the child process.</p>
|
||
<p>On Unix, <a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the <code class="docutils literal notranslate"><span class="pre">close</span></code>
|
||
method result (exit status) into an exit code if it is not <code class="docutils literal notranslate"><span class="pre">None</span></code>. On
|
||
Windows, the <code class="docutils literal notranslate"><span class="pre">close</span></code> method result is directly the exit code
|
||
(or <code class="docutils literal notranslate"><span class="pre">None</span></code>).</p>
|
||
<p>This is implemented using <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a>; see that class’s
|
||
documentation for more powerful ways to manage and communicate with
|
||
subprocesses.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>The <a class="reference internal" href="#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> affects encodings used
|
||
for <em>cmd</em> and pipe contents.</p>
|
||
<p><a class="reference internal" href="#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">popen()</span></code></a> is a simple wrapper around <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a>.
|
||
Use <a class="reference internal" href="subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> or <a class="reference internal" href="subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> to
|
||
control options like encodings.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.posix_spawn">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">posix_spawn</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">argv</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_actions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setpgroup</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resetids</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsid</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsigmask</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsigdef</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scheduler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.posix_spawn" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Wraps the <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code> C library API for use from Python.</p>
|
||
<p>Most users should use <a class="reference internal" href="subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> instead of <a class="reference internal" href="#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a>.</p>
|
||
<p>The positional-only arguments <em>path</em>, <em>args</em>, and <em>env</em> are similar to
|
||
<a class="reference internal" href="#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>. <em>env</em> is allowed to be <code class="docutils literal notranslate"><span class="pre">None</span></code>, in which case current
|
||
process’ environment is used.</p>
|
||
<p>The <em>path</em> parameter is the path to the executable file. The <em>path</em> should
|
||
contain a directory. Use <a class="reference internal" href="#os.posix_spawnp" title="os.posix_spawnp"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawnp()</span></code></a> to pass an executable file
|
||
without directory.</p>
|
||
<p>The <em>file_actions</em> argument may be a sequence of tuples describing actions
|
||
to take on specific file descriptors in the child process between the C
|
||
library implementation’s <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">exec()</span></code> steps.
|
||
The first item in each tuple must be one of the three type indicator
|
||
listed below describing the remaining tuple elements:</p>
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.POSIX_SPAWN_OPEN">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_SPAWN_OPEN</span></span><a class="headerlink" href="#os.POSIX_SPAWN_OPEN" title="Link to this definition">¶</a></dt>
|
||
<dd><p>(<code class="docutils literal notranslate"><span class="pre">os.POSIX_SPAWN_OPEN</span></code>, <em>fd</em>, <em>path</em>, <em>flags</em>, <em>mode</em>)</p>
|
||
<p>Performs <code class="docutils literal notranslate"><span class="pre">os.dup2(os.open(path,</span> <span class="pre">flags,</span> <span class="pre">mode),</span> <span class="pre">fd)</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.POSIX_SPAWN_CLOSE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_SPAWN_CLOSE</span></span><a class="headerlink" href="#os.POSIX_SPAWN_CLOSE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>(<code class="docutils literal notranslate"><span class="pre">os.POSIX_SPAWN_CLOSE</span></code>, <em>fd</em>)</p>
|
||
<p>Performs <code class="docutils literal notranslate"><span class="pre">os.close(fd)</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.POSIX_SPAWN_DUP2">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_SPAWN_DUP2</span></span><a class="headerlink" href="#os.POSIX_SPAWN_DUP2" title="Link to this definition">¶</a></dt>
|
||
<dd><p>(<code class="docutils literal notranslate"><span class="pre">os.POSIX_SPAWN_DUP2</span></code>, <em>fd</em>, <em>new_fd</em>)</p>
|
||
<p>Performs <code class="docutils literal notranslate"><span class="pre">os.dup2(fd,</span> <span class="pre">new_fd)</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.POSIX_SPAWN_CLOSEFROM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">POSIX_SPAWN_CLOSEFROM</span></span><a class="headerlink" href="#os.POSIX_SPAWN_CLOSEFROM" title="Link to this definition">¶</a></dt>
|
||
<dd><p>(<code class="docutils literal notranslate"><span class="pre">os.POSIX_SPAWN_CLOSEFROM</span></code>, <em>fd</em>)</p>
|
||
<p>Performs <code class="docutils literal notranslate"><span class="pre">os.closerange(fd,</span> <span class="pre">INF)</span></code>.</p>
|
||
</dd></dl>
|
||
|
||
<p>These tuples correspond to the C library
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addopen()</span></code>,
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addclose()</span></code>,
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_adddup2()</span></code>, and
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addclosefrom_np()</span></code> API calls used to prepare
|
||
for the <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code> call itself.</p>
|
||
<p>The <em>setpgroup</em> argument will set the process group of the child to the value
|
||
specified. If the value specified is 0, the child’s process group ID will be
|
||
made the same as its process ID. If the value of <em>setpgroup</em> is not set, the
|
||
child will inherit the parent’s process group ID. This argument corresponds
|
||
to the C library <code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETPGROUP</span></code> flag.</p>
|
||
<p>If the <em>resetids</em> argument is <code class="docutils literal notranslate"><span class="pre">True</span></code> it will reset the effective UID and
|
||
GID of the child to the real UID and GID of the parent process. If the
|
||
argument is <code class="docutils literal notranslate"><span class="pre">False</span></code>, then the child retains the effective UID and GID of
|
||
the parent. In either case, if the set-user-ID and set-group-ID permission
|
||
bits are enabled on the executable file, their effect will override the
|
||
setting of the effective UID and GID. This argument corresponds to the C
|
||
library <code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_RESETIDS</span></code> flag.</p>
|
||
<p>If the <em>setsid</em> argument is <code class="docutils literal notranslate"><span class="pre">True</span></code>, it will create a new session ID
|
||
for <code class="docutils literal notranslate"><span class="pre">posix_spawn</span></code>. <em>setsid</em> requires <code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSID</span></code>
|
||
or <code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSID_NP</span></code> flag. Otherwise, <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>
|
||
is raised.</p>
|
||
<p>The <em>setsigmask</em> argument will set the signal mask to the signal set
|
||
specified. If the parameter is not used, then the child inherits the
|
||
parent’s signal mask. This argument corresponds to the C library
|
||
<code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSIGMASK</span></code> flag.</p>
|
||
<p>The <em>sigdef</em> argument will reset the disposition of all signals in the set
|
||
specified. This argument corresponds to the C library
|
||
<code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSIGDEF</span></code> flag.</p>
|
||
<p>The <em>scheduler</em> argument must be a tuple containing the (optional) scheduler
|
||
policy and an instance of <a class="reference internal" href="#os.sched_param" title="os.sched_param"><code class="xref py py-class docutils literal notranslate"><span class="pre">sched_param</span></code></a> with the scheduler parameters.
|
||
A value of <code class="docutils literal notranslate"><span class="pre">None</span></code> in the place of the scheduler policy indicates that is
|
||
not being provided. This argument is a combination of the C library
|
||
<code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSCHEDPARAM</span></code> and <code class="xref c c-macro docutils literal notranslate"><span class="pre">POSIX_SPAWN_SETSCHEDULER</span></code>
|
||
flags.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.posix_spawn</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">argv</span></code>, <code class="docutils literal notranslate"><span class="pre">env</span></code>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span><em>env</em> parameter accepts <code class="docutils literal notranslate"><span class="pre">None</span></code>.
|
||
<code class="docutils literal notranslate"><span class="pre">os.POSIX_SPAWN_CLOSEFROM</span></code> is available on platforms where
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addclosefrom_np()</span></code> exists.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.posix_spawnp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">posix_spawnp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">argv</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_actions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setpgroup</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resetids</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsid</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsigmask</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">setsigdef</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scheduler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.posix_spawnp" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Wraps the <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawnp()</span></code> C library API for use from Python.</p>
|
||
<p>Similar to <a class="reference internal" href="#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> except that the system searches
|
||
for the <em>executable</em> file in the list of directories specified by the
|
||
<span class="target" id="index-39"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable (in the same way as for <code class="docutils literal notranslate"><span class="pre">execvp(3)</span></code>).</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.posix_spawn</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">argv</span></code>, <code class="docutils literal notranslate"><span class="pre">env</span></code>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.8.</span></p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: POSIX, not WASI, not Android, not iOS.</p>
|
||
<p>See <a class="reference internal" href="#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> documentation.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.register_at_fork">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">register_at_fork</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">before</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">after_in_parent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">after_in_child</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.register_at_fork" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Register callables to be executed when a new child process is forked
|
||
using <a class="reference internal" href="#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a> or similar process cloning APIs.
|
||
The parameters are optional and keyword-only.
|
||
Each specifies a different call point.</p>
|
||
<ul class="simple">
|
||
<li><p><em>before</em> is a function called before forking a child process.</p></li>
|
||
<li><p><em>after_in_parent</em> is a function called from the parent process
|
||
after forking a child process.</p></li>
|
||
<li><p><em>after_in_child</em> is a function called from the child process.</p></li>
|
||
</ul>
|
||
<p>These calls are only made if control is expected to return to the
|
||
Python interpreter. A typical <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> launch will not
|
||
trigger them as the child is not going to re-enter the interpreter.</p>
|
||
<p>Functions registered for execution before forking are called in
|
||
reverse registration order. Functions registered for execution
|
||
after forking (either in the parent or in the child) are called
|
||
in registration order.</p>
|
||
<p>Note that <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> calls made by third-party C code may not
|
||
call those functions, unless it explicitly calls <a class="reference internal" href="../c-api/sys.html#c.PyOS_BeforeFork" title="PyOS_BeforeFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_BeforeFork()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Parent" title="PyOS_AfterFork_Parent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Parent()</span></code></a> and <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a>.</p>
|
||
<p>There is no way to unregister a function.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.7.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.spawnl">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnl" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnle">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnle" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnlp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnlp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnlp" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnlpe">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnlpe</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnlpe" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnv">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnv" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnve">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnve" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnvp">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnvp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnvp" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.spawnvpe">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">spawnvpe</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">env</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.spawnvpe" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Execute the program <em>path</em> in a new process.</p>
|
||
<p>(Note that the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module provides more powerful facilities for
|
||
spawning new processes and retrieving their results; using that module is
|
||
preferable to using these functions. Check especially the
|
||
<a class="reference internal" href="subprocess.html#subprocess-replacements"><span class="std std-ref">Replacing Older Functions with the subprocess Module</span></a> section.)</p>
|
||
<p>If <em>mode</em> is <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_NOWAIT</span></code></a>, this function returns the process id of the new
|
||
process; if <em>mode</em> is <a class="reference internal" href="#os.P_WAIT" title="os.P_WAIT"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_WAIT</span></code></a>, returns the process’s exit code if it
|
||
exits normally, or <code class="docutils literal notranslate"><span class="pre">-signal</span></code>, where <em>signal</em> is the signal that killed the
|
||
process. On Windows, the process id will actually be the process handle, so can
|
||
be used with the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> function.</p>
|
||
<p>Note on VxWorks, this function doesn’t return <code class="docutils literal notranslate"><span class="pre">-signal</span></code> when the new process is
|
||
killed. Instead it raises OSError exception.</p>
|
||
<p>The “l” and “v” variants of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> functions differ in how
|
||
command-line arguments are passed. The “l” variants are perhaps the easiest
|
||
to work with if the number of parameters is fixed when the code is written; the
|
||
individual parameters simply become additional parameters to the
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">spawnl*()</span></code> functions. The “v” variants are good when the number of
|
||
parameters is variable, with the arguments being passed in a list or tuple as
|
||
the <em>args</em> parameter. In either case, the arguments to the child process must
|
||
start with the name of the command being run.</p>
|
||
<p>The variants which include a second “p” near the end (<a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlp()</span></code></a>,
|
||
<a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvp()</span></code></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvpe()</span></code></a>) will use the
|
||
<span class="target" id="index-40"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to locate the program <em>file</em>. When the
|
||
environment is being replaced (using one of the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*e</span></code></a> variants,
|
||
discussed in the next paragraph), the new environment is used as the source of
|
||
the <span class="target" id="index-41"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> variable. The other variants, <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnl()</span></code></a>,
|
||
<a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnle()</span></code></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnv()</span></code></a>, and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnve()</span></code></a>, will not use the
|
||
<span class="target" id="index-42"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> variable to locate the executable; <em>path</em> must contain an
|
||
appropriate absolute or relative path.</p>
|
||
<p>For <a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnle()</span></code></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnve()</span></code></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvpe()</span></code></a>
|
||
(note that these all end in “e”), the <em>env</em> parameter must be a mapping
|
||
which is used to define the environment variables for the new process (they are
|
||
used instead of the current process’ environment); the functions
|
||
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnl()</span></code></a>, <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlp()</span></code></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnv()</span></code></a>, and <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvp()</span></code></a> all cause
|
||
the new process to inherit the environment of the current process. Note that
|
||
keys and values in the <em>env</em> dictionary must be strings; invalid keys or
|
||
values will cause the function to fail, with a return value of <code class="docutils literal notranslate"><span class="pre">127</span></code>.</p>
|
||
<p>As an example, the following calls to <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlp()</span></code></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvpe()</span></code></a> are
|
||
equivalent:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">spawnlp</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s1">'cp'</span><span class="p">,</span> <span class="s1">'cp'</span><span class="p">,</span> <span class="s1">'index.html'</span><span class="p">,</span> <span class="s1">'/dev/null'</span><span class="p">)</span>
|
||
|
||
<span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'cp'</span><span class="p">,</span> <span class="s1">'index.html'</span><span class="p">,</span> <span class="s1">'/dev/null'</span><span class="p">]</span>
|
||
<span class="n">os</span><span class="o">.</span><span class="n">spawnvpe</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s1">'cp'</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.spawn</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">mode</span></code>, <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">args</span></code>, <code class="docutils literal notranslate"><span class="pre">env</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not Android, not iOS.</p>
|
||
<p><a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlp()</span></code></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnlpe()</span></code></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvp()</span></code></a>
|
||
and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnvpe()</span></code></a> are not available on Windows. <a class="reference internal" href="#os.spawnle" title="os.spawnle"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnle()</span></code></a> and
|
||
<a class="reference internal" href="#os.spawnve" title="os.spawnve"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawnve()</span></code></a> are not thread-safe on Windows; we advise you to use the
|
||
<a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module instead.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.P_NOWAIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_NOWAIT</span></span><a class="headerlink" href="#os.P_NOWAIT" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.P_NOWAITO">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_NOWAITO</span></span><a class="headerlink" href="#os.P_NOWAITO" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> family of
|
||
functions. If either of these values is given, the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> functions
|
||
will return as soon as the new process has been created, with the process id as
|
||
the return value.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.P_WAIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_WAIT</span></span><a class="headerlink" href="#os.P_WAIT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Possible value for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> family of
|
||
functions. If this is given as <em>mode</em>, the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> functions will not
|
||
return until the new process has run to completion and will return the exit code
|
||
of the process the run is successful, or <code class="docutils literal notranslate"><span class="pre">-signal</span></code> if a signal kills the
|
||
process.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.P_DETACH">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_DETACH</span></span><a class="headerlink" href="#os.P_DETACH" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.P_OVERLAY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_OVERLAY</span></span><a class="headerlink" href="#os.P_OVERLAY" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Possible values for the <em>mode</em> parameter to the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> family of
|
||
functions. These are less portable than those listed above. <a class="reference internal" href="#os.P_DETACH" title="os.P_DETACH"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_DETACH</span></code></a>
|
||
is similar to <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_NOWAIT</span></code></a>, but the new process is detached from the
|
||
console of the calling process. If <a class="reference internal" href="#os.P_OVERLAY" title="os.P_OVERLAY"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_OVERLAY</span></code></a> is used, the current
|
||
process will be replaced; the <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a> function will not return.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.startfile">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">startfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">operation</span></span></em><span class="optional">]</span><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">arguments</span></span></em><span class="optional">]</span><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">cwd</span></span></em><span class="optional">]</span><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">show_cmd</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#os.startfile" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Start a file with its associated application.</p>
|
||
<p>When <em>operation</em> is not specified, this acts like double-clicking
|
||
the file in Windows Explorer, or giving the file name as an argument to the
|
||
<strong class="program">start</strong> command from the interactive command shell: the file is opened
|
||
with whatever application (if any) its extension is associated.</p>
|
||
<p>When another <em>operation</em> is given, it must be a “command verb” that specifies
|
||
what should be done with the file. Common verbs documented by Microsoft are <code class="docutils literal notranslate"><span class="pre">'open'</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">'print'</span></code> and <code class="docutils literal notranslate"><span class="pre">'edit'</span></code> (to be used on files) as well as <code class="docutils literal notranslate"><span class="pre">'explore'</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">'find'</span></code> (to be used on directories).</p>
|
||
<p>When launching an application, specify <em>arguments</em> to be passed as a single
|
||
string. This argument may have no effect when using this function to launch a
|
||
document.</p>
|
||
<p>The default working directory is inherited, but may be overridden by the <em>cwd</em>
|
||
argument. This should be an absolute path. A relative <em>path</em> will be resolved
|
||
against this argument.</p>
|
||
<p>Use <em>show_cmd</em> to override the default window style. Whether this has any
|
||
effect will depend on the application being launched. Values are integers as
|
||
supported by the Win32 <code class="xref c c-func docutils literal notranslate"><span class="pre">ShellExecute()</span></code> function.</p>
|
||
<p><a class="reference internal" href="#os.startfile" title="os.startfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">startfile()</span></code></a> returns as soon as the associated application is launched.
|
||
There is no option to wait for the application to close, and no way to retrieve
|
||
the application’s exit status. The <em>path</em> parameter is relative to the current
|
||
directory or <em>cwd</em>. If you want to use an absolute path, make sure the first
|
||
character is not a slash (<code class="docutils literal notranslate"><span class="pre">'/'</span></code>) Use <a class="reference internal" href="pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> or the
|
||
<a class="reference internal" href="os.path.html#os.path.normpath" title="os.path.normpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.normpath()</span></code></a> function to ensure that paths are properly encoded for
|
||
Win32.</p>
|
||
<p>To reduce interpreter startup overhead, the Win32 <code class="xref c c-func docutils literal notranslate"><span class="pre">ShellExecute()</span></code>
|
||
function is not resolved until this function is first called. If the function
|
||
cannot be resolved, <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> will be raised.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.startfile</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">operation</span></code>.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.startfile/2</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">path</span></code>, <code class="docutils literal notranslate"><span class="pre">operation</span></code>, <code class="docutils literal notranslate"><span class="pre">arguments</span></code>, <code class="docutils literal notranslate"><span class="pre">cwd</span></code>, <code class="docutils literal notranslate"><span class="pre">show_cmd</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.10: </span>Added the <em>arguments</em>, <em>cwd</em> and <em>show_cmd</em> arguments, and the
|
||
<code class="docutils literal notranslate"><span class="pre">os.startfile/2</span></code> audit event.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.system">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">system</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">command</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.system" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Execute the command (a string) in a subshell. This is implemented by calling
|
||
the Standard C function <code class="xref c c-func docutils literal notranslate"><span class="pre">system()</span></code>, and has the same limitations.
|
||
Changes to <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, etc. are not reflected in the environment of
|
||
the executed command. If <em>command</em> generates any output, it will be sent to
|
||
the interpreter standard output stream. The C standard does not
|
||
specify the meaning of the return value of the C function, so the return
|
||
value of the Python function is system-dependent.</p>
|
||
<p>On Unix, the return value is the exit status of the process encoded in the
|
||
format specified for <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>.</p>
|
||
<p>On Windows, the return value is that returned by the system shell after
|
||
running <em>command</em>. The shell is given by the Windows environment variable
|
||
<span class="target" id="index-43"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">COMSPEC</span></code>: it is usually <strong class="program">cmd.exe</strong>, which returns the exit
|
||
status of the command run; on systems using a non-native shell, consult your
|
||
shell documentation.</p>
|
||
<p>The <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module provides more powerful facilities for spawning
|
||
new processes and retrieving their results; using that module is preferable
|
||
to using this function. See the <a class="reference internal" href="subprocess.html#subprocess-replacements"><span class="std std-ref">Replacing Older Functions with the subprocess Module</span></a> section in
|
||
the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> documentation for some helpful recipes.</p>
|
||
<p>On Unix, <a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the result
|
||
(exit status) into an exit code. On Windows, the result is directly the exit
|
||
code.</p>
|
||
<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">os.system</span></code> with argument <code class="docutils literal notranslate"><span class="pre">command</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.times">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">times</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.times" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Returns the current global process times.
|
||
The return value is an object with five attributes:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">user</span></code> - user time</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">system</span></code> - system time</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">children_user</span></code> - user time of all child processes</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">children_system</span></code> - system time of all child processes</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">elapsed</span></code> - elapsed real time since a fixed point in the past</p></li>
|
||
</ul>
|
||
<p>For backwards compatibility, this object also behaves like a five-tuple
|
||
containing <code class="xref py py-attr docutils literal notranslate"><span class="pre">user</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">system</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">children_user</span></code>,
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">children_system</span></code>, and <code class="xref py py-attr docutils literal notranslate"><span class="pre">elapsed</span></code> in that order.</p>
|
||
<p>See the Unix manual page
|
||
<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/times(2)">times(2)</a></em> and <a class="reference external" href="https://man.freebsd.org/cgi/man.cgi?time(3)">times(3)</a> manual page on Unix or <a class="reference external" href="https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocesstimes">the GetProcessTimes MSDN</a>
|
||
on Windows. On Windows, only <code class="xref py py-attr docutils literal notranslate"><span class="pre">user</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">system</span></code> are known; the other attributes are zero.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.3: </span>Return type changed from a tuple to a tuple-like object
|
||
with named attributes.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.wait">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">wait</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.wait" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Wait for completion of a child process, and return a tuple containing its pid
|
||
and exit status indication: a 16-bit number, whose low byte is the signal number
|
||
that killed the process, and whose high byte is the exit status (if the signal
|
||
number is zero); the high bit of the low byte is set if a core file was
|
||
produced.</p>
|
||
<p>If there are no children that could be waited for, <a class="reference internal" href="exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a>
|
||
is raised.</p>
|
||
<p><a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the exit status into an
|
||
exit code.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The other <code class="xref py py-func docutils literal notranslate"><span class="pre">wait*()</span></code> functions documented below can be used to wait for the
|
||
completion of a specific child process and have more options.
|
||
<a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> is the only one also available on Windows.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.waitid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">waitid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">idtype</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.waitid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Wait for the completion of a child process.</p>
|
||
<p><em>idtype</em> can be <a class="reference internal" href="#os.P_PID" title="os.P_PID"><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PID</span></code></a>, <a class="reference internal" href="#os.P_PGID" title="os.P_PGID"><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PGID</span></code></a>, <a class="reference internal" href="#os.P_ALL" title="os.P_ALL"><code class="xref py py-data docutils literal notranslate"><span class="pre">P_ALL</span></code></a>, or (on Linux) <a class="reference internal" href="#os.P_PIDFD" title="os.P_PIDFD"><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PIDFD</span></code></a>.
|
||
The interpretation of <em>id</em> depends on it; see their individual descriptions.</p>
|
||
<p><em>options</em> is an OR combination of flags. At least one of <a class="reference internal" href="#os.WEXITED" title="os.WEXITED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WEXITED</span></code></a>,
|
||
<a class="reference internal" href="#os.WSTOPPED" title="os.WSTOPPED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WSTOPPED</span></code></a> or <a class="reference internal" href="#os.WCONTINUED" title="os.WCONTINUED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WCONTINUED</span></code></a> is required;
|
||
<a class="reference internal" href="#os.WNOHANG" title="os.WNOHANG"><code class="xref py py-data docutils literal notranslate"><span class="pre">WNOHANG</span></code></a> and <a class="reference internal" href="#os.WNOWAIT" title="os.WNOWAIT"><code class="xref py py-data docutils literal notranslate"><span class="pre">WNOWAIT</span></code></a> are additional optional flags.</p>
|
||
<p>The return value is an object representing the data contained in the
|
||
<code class="xref c c-type docutils literal notranslate"><span class="pre">siginfo_t</span></code> structure with the following attributes:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">si_pid</span></code> (process ID)</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">si_uid</span></code> (real user ID of the child)</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">si_signo</span></code> (always <a class="reference internal" href="signal.html#signal.SIGCHLD" title="signal.SIGCHLD"><code class="xref py py-const docutils literal notranslate"><span class="pre">SIGCHLD</span></code></a>)</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">si_status</span></code> (the exit status or signal number, depending on <code class="xref py py-attr docutils literal notranslate"><span class="pre">si_code</span></code>)</p></li>
|
||
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">si_code</span></code> (see <a class="reference internal" href="#os.CLD_EXITED" title="os.CLD_EXITED"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLD_EXITED</span></code></a> for possible values)</p></li>
|
||
</ul>
|
||
<p>If <a class="reference internal" href="#os.WNOHANG" title="os.WNOHANG"><code class="xref py py-data docutils literal notranslate"><span class="pre">WNOHANG</span></code></a> is specified and there are no matching children in the
|
||
requested state, <code class="docutils literal notranslate"><span class="pre">None</span></code> is returned.
|
||
Otherwise, if there are no matching children
|
||
that could be waited for, <a class="reference internal" href="exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a> is raised.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>This function is now available on macOS as well.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.waitpid">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">waitpid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.waitpid" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The details of this function differ on Unix and Windows.</p>
|
||
<p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and
|
||
return a tuple containing its process id and exit status indication (encoded as
|
||
for <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>). The semantics of the call are affected by the value of the
|
||
integer <em>options</em>, which should be <code class="docutils literal notranslate"><span class="pre">0</span></code> for normal operation.</p>
|
||
<p>If <em>pid</em> is greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> requests status information for
|
||
that specific process. If <em>pid</em> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, the request is for the status of any
|
||
child in the process group of the current process. If <em>pid</em> is <code class="docutils literal notranslate"><span class="pre">-1</span></code>, the
|
||
request pertains to any child of the current process. If <em>pid</em> is less than
|
||
<code class="docutils literal notranslate"><span class="pre">-1</span></code>, status is requested for any process in the process group <code class="docutils literal notranslate"><span class="pre">-pid</span></code> (the
|
||
absolute value of <em>pid</em>).</p>
|
||
<p><em>options</em> is an OR combination of flags. If it contains <a class="reference internal" href="#os.WNOHANG" title="os.WNOHANG"><code class="xref py py-data docutils literal notranslate"><span class="pre">WNOHANG</span></code></a> and
|
||
there are no matching children in the requested state, <code class="docutils literal notranslate"><span class="pre">(0,</span> <span class="pre">0)</span></code> is
|
||
returned. Otherwise, if there are no matching children that could be waited
|
||
for, <a class="reference internal" href="exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a> is raised. Other options that can be used are
|
||
<a class="reference internal" href="#os.WUNTRACED" title="os.WUNTRACED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WUNTRACED</span></code></a> and <a class="reference internal" href="#os.WCONTINUED" title="os.WCONTINUED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WCONTINUED</span></code></a>.</p>
|
||
<p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and
|
||
return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits
|
||
(shifting makes cross-platform use of the function easier). A <em>pid</em> less than or
|
||
equal to <code class="docutils literal notranslate"><span class="pre">0</span></code> has no special meaning on Windows, and raises an exception. The
|
||
value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose
|
||
id is known, not necessarily a child process. The <a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*</span></code></a>
|
||
functions called with <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><code class="xref py py-const docutils literal notranslate"><span class="pre">P_NOWAIT</span></code></a> return suitable process handles.</p>
|
||
<p><a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the exit status into an
|
||
exit code.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>If the system call is interrupted and the signal handler does not raise an
|
||
exception, the function now retries the system call instead of raising an
|
||
<a class="reference internal" href="exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> exception (see <span class="target" id="index-44"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale).</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.wait3">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">wait3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.wait3" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, except no process id argument is given and a
|
||
3-element tuple containing the child’s process id, exit status indication,
|
||
and resource usage information is returned. Refer to
|
||
<a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">resource.getrusage()</span></code></a> for details on resource usage information. The
|
||
<em>options</em> argument is the same as that provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> and
|
||
<a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a>.</p>
|
||
<p><a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the exit status into an
|
||
exitcode.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.wait4">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">wait4</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.wait4" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, except a 3-element tuple, containing the child’s
|
||
process id, exit status indication, and resource usage information is
|
||
returned. Refer to <a class="reference internal" href="resource.html#resource.getrusage" title="resource.getrusage"><code class="xref py py-func docutils literal notranslate"><span class="pre">resource.getrusage()</span></code></a> for details on resource usage
|
||
information. The arguments to <a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a> are the same as those provided
|
||
to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>.</p>
|
||
<p><a class="reference internal" href="#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitstatus_to_exitcode()</span></code></a> can be used to convert the exit status into an
|
||
exitcode.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.P_PID">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_PID</span></span><a class="headerlink" href="#os.P_PID" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.P_PGID">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_PGID</span></span><a class="headerlink" href="#os.P_PGID" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.P_ALL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_ALL</span></span><a class="headerlink" href="#os.P_ALL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.P_PIDFD">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">P_PIDFD</span></span><a class="headerlink" href="#os.P_PIDFD" title="Link to this definition">¶</a></dt>
|
||
<dd><p>These are the possible values for <em>idtype</em> in <a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>. They affect
|
||
how <em>id</em> is interpreted:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PID</span></code> - wait for the child whose PID is <em>id</em>.</p></li>
|
||
<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PGID</span></code> - wait for any child whose progress group ID is <em>id</em>.</p></li>
|
||
<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">P_ALL</span></code> - wait for any child; <em>id</em> is ignored.</p></li>
|
||
<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PIDFD</span></code> - wait for the child identified by the file descriptor
|
||
<em>id</em> (a process file descriptor created with <a class="reference internal" href="#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">pidfd_open()</span></code></a>).</p></li>
|
||
</ul>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p><code class="xref py py-data docutils literal notranslate"><span class="pre">P_PIDFD</span></code> is only available on Linux >= 5.4.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.9: </span>The <code class="xref py py-data docutils literal notranslate"><span class="pre">P_PIDFD</span></code> constant.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WCONTINUED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WCONTINUED</span></span><a class="headerlink" href="#os.WCONTINUED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, <a class="reference internal" href="#os.wait3" title="os.wait3"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait3()</span></code></a>, <a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a>, and
|
||
<a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a> causes child processes to be reported if they have been
|
||
continued from a job control stop since they were last reported.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WEXITED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WEXITED</span></span><a class="headerlink" href="#os.WEXITED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag for <a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a> causes child processes that have terminated to
|
||
be reported.</p>
|
||
<p>The other <code class="docutils literal notranslate"><span class="pre">wait*</span></code> functions always report children that have terminated,
|
||
so this option is not available for them.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WSTOPPED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WSTOPPED</span></span><a class="headerlink" href="#os.WSTOPPED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag for <a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a> causes child processes that have been stopped
|
||
by the delivery of a signal to be reported.</p>
|
||
<p>This option is not available for the other <code class="docutils literal notranslate"><span class="pre">wait*</span></code> functions.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WUNTRACED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WUNTRACED</span></span><a class="headerlink" href="#os.WUNTRACED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, <a class="reference internal" href="#os.wait3" title="os.wait3"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait3()</span></code></a>, and <a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a> causes
|
||
child processes to also be reported if they have been stopped but their
|
||
current state has not been reported since they were stopped.</p>
|
||
<p>This option is not available for <a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WNOHANG">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WNOHANG</span></span><a class="headerlink" href="#os.WNOHANG" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag causes <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, <a class="reference internal" href="#os.wait3" title="os.wait3"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait3()</span></code></a>, <a class="reference internal" href="#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a>, and
|
||
<a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a> to return right away if no child process status is available
|
||
immediately.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.WNOWAIT">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WNOWAIT</span></span><a class="headerlink" href="#os.WNOWAIT" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This <em>options</em> flag causes <a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a> to leave the child in a waitable state, so that
|
||
a later <code class="xref py py-func docutils literal notranslate"><span class="pre">wait*()</span></code> call can be used to retrieve the child status information again.</p>
|
||
<p>This option is not available for the other <code class="docutils literal notranslate"><span class="pre">wait*</span></code> functions.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.CLD_EXITED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_EXITED</span></span><a class="headerlink" href="#os.CLD_EXITED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLD_KILLED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_KILLED</span></span><a class="headerlink" href="#os.CLD_KILLED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLD_DUMPED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_DUMPED</span></span><a class="headerlink" href="#os.CLD_DUMPED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLD_TRAPPED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_TRAPPED</span></span><a class="headerlink" href="#os.CLD_TRAPPED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLD_STOPPED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_STOPPED</span></span><a class="headerlink" href="#os.CLD_STOPPED" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.CLD_CONTINUED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">CLD_CONTINUED</span></span><a class="headerlink" href="#os.CLD_CONTINUED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>These are the possible values for <code class="xref py py-attr docutils literal notranslate"><span class="pre">si_code</span></code> in the result returned by
|
||
<a class="reference internal" href="#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.9: </span>Added <a class="reference internal" href="#os.CLD_KILLED" title="os.CLD_KILLED"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLD_KILLED</span></code></a> and <a class="reference internal" href="#os.CLD_STOPPED" title="os.CLD_STOPPED"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLD_STOPPED</span></code></a> values.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.waitstatus_to_exitcode">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">waitstatus_to_exitcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.waitstatus_to_exitcode" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Convert a wait status to an exit code.</p>
|
||
<p>On Unix:</p>
|
||
<ul class="simple">
|
||
<li><p>If the process exited normally (if <code class="docutils literal notranslate"><span class="pre">WIFEXITED(status)</span></code> is true),
|
||
return the process exit status (return <code class="docutils literal notranslate"><span class="pre">WEXITSTATUS(status)</span></code>):
|
||
result greater than or equal to 0.</p></li>
|
||
<li><p>If the process was terminated by a signal (if <code class="docutils literal notranslate"><span class="pre">WIFSIGNALED(status)</span></code> is
|
||
true), return <code class="docutils literal notranslate"><span class="pre">-signum</span></code> where <em>signum</em> is the number of the signal that
|
||
caused the process to terminate (return <code class="docutils literal notranslate"><span class="pre">-WTERMSIG(status)</span></code>):
|
||
result less than 0.</p></li>
|
||
<li><p>Otherwise, raise a <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.</p></li>
|
||
</ul>
|
||
<p>On Windows, return <em>status</em> shifted right by 8 bits.</p>
|
||
<p>On Unix, if the process is being traced or if <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> was called
|
||
with <a class="reference internal" href="#os.WUNTRACED" title="os.WUNTRACED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WUNTRACED</span></code></a> option, the caller must first check if
|
||
<code class="docutils literal notranslate"><span class="pre">WIFSTOPPED(status)</span></code> is true. This function must not be called if
|
||
<code class="docutils literal notranslate"><span class="pre">WIFSTOPPED(status)</span></code> is true.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><a class="reference internal" href="#os.WIFEXITED" title="os.WIFEXITED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFEXITED()</span></code></a>, <a class="reference internal" href="#os.WEXITSTATUS" title="os.WEXITSTATUS"><code class="xref py py-func docutils literal notranslate"><span class="pre">WEXITSTATUS()</span></code></a>, <a class="reference internal" href="#os.WIFSIGNALED" title="os.WIFSIGNALED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSIGNALED()</span></code></a>,
|
||
<a class="reference internal" href="#os.WTERMSIG" title="os.WTERMSIG"><code class="xref py py-func docutils literal notranslate"><span class="pre">WTERMSIG()</span></code></a>, <a class="reference internal" href="#os.WIFSTOPPED" title="os.WIFSTOPPED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSTOPPED()</span></code></a>, <a class="reference internal" href="#os.WSTOPSIG" title="os.WSTOPSIG"><code class="xref py py-func docutils literal notranslate"><span class="pre">WSTOPSIG()</span></code></a> functions.</p>
|
||
</div>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, Windows, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.9.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>The following functions take a process status code as returned by
|
||
<a class="reference internal" href="#os.system" title="os.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">system()</span></code></a>, <a class="reference internal" href="#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>, or <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> as a parameter. They may be
|
||
used to determine the disposition of a process.</p>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WCOREDUMP">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WCOREDUMP</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WCOREDUMP" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if a core dump was generated for the process, otherwise
|
||
return <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<p>This function should be employed only if <a class="reference internal" href="#os.WIFSIGNALED" title="os.WIFSIGNALED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSIGNALED()</span></code></a> is true.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WIFCONTINUED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WIFCONTINUED</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFCONTINUED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if a stopped child has been resumed by delivery of
|
||
<a class="reference internal" href="signal.html#signal.SIGCONT" title="signal.SIGCONT"><code class="xref py py-const docutils literal notranslate"><span class="pre">SIGCONT</span></code></a> (if the process has been continued from a job
|
||
control stop), otherwise return <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<p>See <a class="reference internal" href="#os.WCONTINUED" title="os.WCONTINUED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WCONTINUED</span></code></a> option.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WIFSTOPPED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WIFSTOPPED</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFSTOPPED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the process was stopped by delivery of a signal,
|
||
otherwise return <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<p><a class="reference internal" href="#os.WIFSTOPPED" title="os.WIFSTOPPED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSTOPPED()</span></code></a> only returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a> call was
|
||
done using <a class="reference internal" href="#os.WUNTRACED" title="os.WUNTRACED"><code class="xref py py-data docutils literal notranslate"><span class="pre">WUNTRACED</span></code></a> option or when the process is being traced (see
|
||
<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/ptrace(2)">ptrace(2)</a></em>).</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WIFSIGNALED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WIFSIGNALED</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFSIGNALED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the process was terminated by a signal, otherwise return
|
||
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WIFEXITED">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WIFEXITED</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WIFEXITED" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the process exited terminated normally, that is,
|
||
by calling <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">_exit()</span></code>, or by returning from <code class="docutils literal notranslate"><span class="pre">main()</span></code>;
|
||
otherwise return <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WEXITSTATUS">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WEXITSTATUS</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WEXITSTATUS" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the process exit status.</p>
|
||
<p>This function should be employed only if <a class="reference internal" href="#os.WIFEXITED" title="os.WIFEXITED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFEXITED()</span></code></a> is true.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WSTOPSIG">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WSTOPSIG</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WSTOPSIG" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the signal which caused the process to stop.</p>
|
||
<p>This function should be employed only if <a class="reference internal" href="#os.WIFSTOPPED" title="os.WIFSTOPPED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSTOPPED()</span></code></a> is true.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.WTERMSIG">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">WTERMSIG</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">status</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.WTERMSIG" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the number of the signal that caused the process to terminate.</p>
|
||
<p>This function should be employed only if <a class="reference internal" href="#os.WIFSIGNALED" title="os.WIFSIGNALED"><code class="xref py py-func docutils literal notranslate"><span class="pre">WIFSIGNALED()</span></code></a> is true.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not WASI, not Android, not iOS.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="interface-to-the-scheduler">
|
||
<h2>Interface to the scheduler<a class="headerlink" href="#interface-to-the-scheduler" title="Link to this heading">¶</a></h2>
|
||
<p>These functions control how a process is allocated CPU time by the operating
|
||
system. They are only available on some Unix platforms. For more detailed
|
||
information, consult your Unix manpages.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
<p>The following scheduling policies are exposed if they are supported by the
|
||
operating system.</p>
|
||
<dl class="py data" id="os-scheduling-policy">
|
||
<dt class="sig sig-object py" id="os.SCHED_OTHER">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_OTHER</span></span><a class="headerlink" href="#os.SCHED_OTHER" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The default scheduling policy.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_BATCH">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_BATCH</span></span><a class="headerlink" href="#os.SCHED_BATCH" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Scheduling policy for CPU-intensive processes that tries to preserve
|
||
interactivity on the rest of the computer.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_IDLE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_IDLE</span></span><a class="headerlink" href="#os.SCHED_IDLE" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Scheduling policy for extremely low priority background tasks.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_SPORADIC">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_SPORADIC</span></span><a class="headerlink" href="#os.SCHED_SPORADIC" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Scheduling policy for sporadic server programs.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_FIFO">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_FIFO</span></span><a class="headerlink" href="#os.SCHED_FIFO" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A First In First Out scheduling policy.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_RR">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_RR</span></span><a class="headerlink" href="#os.SCHED_RR" title="Link to this definition">¶</a></dt>
|
||
<dd><p>A round-robin scheduling policy.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.SCHED_RESET_ON_FORK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">SCHED_RESET_ON_FORK</span></span><a class="headerlink" href="#os.SCHED_RESET_ON_FORK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This flag can be OR’ed with any other scheduling policy. When a process with
|
||
this flag set forks, its child’s scheduling policy and priority are reset to
|
||
the default.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt class="sig sig-object py" id="os.sched_param">
|
||
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_param</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sched_priority</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_param" title="Link to this definition">¶</a></dt>
|
||
<dd><p>This class represents tunable scheduling parameters used in
|
||
<a class="reference internal" href="#os.sched_setparam" title="os.sched_setparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setparam()</span></code></a>, <a class="reference internal" href="#os.sched_setscheduler" title="os.sched_setscheduler"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setscheduler()</span></code></a>, and
|
||
<a class="reference internal" href="#os.sched_getparam" title="os.sched_getparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getparam()</span></code></a>. It is immutable.</p>
|
||
<p>At the moment, there is only one possible parameter:</p>
|
||
<dl class="py attribute">
|
||
<dt class="sig sig-object py" id="os.sched_param.sched_priority">
|
||
<span class="sig-name descname"><span class="pre">sched_priority</span></span><a class="headerlink" href="#os.sched_param.sched_priority" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The scheduling priority for a scheduling policy.</p>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_get_priority_min">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_get_priority_min</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">policy</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_get_priority_min" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the minimum priority value for <em>policy</em>. <em>policy</em> is one of the
|
||
scheduling policy constants above.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_get_priority_max">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_get_priority_max</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">policy</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_get_priority_max" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the maximum priority value for <em>policy</em>. <em>policy</em> is one of the
|
||
scheduling policy constants above.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_setscheduler">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_setscheduler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">policy</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">param</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_setscheduler" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the scheduling policy for the process with PID <em>pid</em>. A <em>pid</em> of 0 means
|
||
the calling process. <em>policy</em> is one of the scheduling policy constants
|
||
above. <em>param</em> is a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><code class="xref py py-class docutils literal notranslate"><span class="pre">sched_param</span></code></a> instance.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_getscheduler">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_getscheduler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_getscheduler" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the scheduling policy for the process with PID <em>pid</em>. A <em>pid</em> of 0
|
||
means the calling process. The result is one of the scheduling policy
|
||
constants above.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_setparam">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_setparam</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">param</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_setparam" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Set the scheduling parameters for the process with PID <em>pid</em>. A <em>pid</em> of 0 means
|
||
the calling process. <em>param</em> is a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><code class="xref py py-class docutils literal notranslate"><span class="pre">sched_param</span></code></a> instance.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_getparam">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_getparam</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_getparam" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the scheduling parameters as a <a class="reference internal" href="#os.sched_param" title="os.sched_param"><code class="xref py py-class docutils literal notranslate"><span class="pre">sched_param</span></code></a> instance for the
|
||
process with PID <em>pid</em>. A <em>pid</em> of 0 means the calling process.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_rr_get_interval">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_rr_get_interval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_rr_get_interval" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the round-robin quantum in seconds for the process with PID <em>pid</em>. A
|
||
<em>pid</em> of 0 means the calling process.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_yield">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_yield</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_yield" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Voluntarily relinquish the CPU. See <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/sched_yield(2)">sched_yield(2)</a></em> for details.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_setaffinity">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_setaffinity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mask</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_setaffinity" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Restrict the process with PID <em>pid</em> (or the current process if zero) to a
|
||
set of CPUs. <em>mask</em> is an iterable of integers representing the set of
|
||
CPUs to which the process should be restricted.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sched_getaffinity">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sched_getaffinity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pid</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sched_getaffinity" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the set of CPUs the process with PID <em>pid</em> is restricted to.</p>
|
||
<p>If <em>pid</em> is zero, return the set of CPUs the calling thread of the current
|
||
process is restricted to.</p>
|
||
<p>See also the <a class="reference internal" href="#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_cpu_count()</span></code></a> function.</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="miscellaneous-system-information">
|
||
<span id="os-path"></span><h2>Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Link to this heading">¶</a></h2>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.confstr">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">confstr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.confstr" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return string-valued system configuration values. <em>name</em> specifies the
|
||
configuration value to retrieve; it may be a string which is the name of a
|
||
defined system value; these names are specified in a number of standards (POSIX,
|
||
Unix 95, Unix 98, and others). Some platforms define additional names as well.
|
||
The names known to the host operating system are given as the keys of the
|
||
<code class="docutils literal notranslate"><span class="pre">confstr_names</span></code> dictionary. For configuration variables not included in that
|
||
mapping, passing an integer for <em>name</em> is also accepted.</p>
|
||
<p>If the configuration value specified by <em>name</em> isn’t defined, <code class="docutils literal notranslate"><span class="pre">None</span></code> is
|
||
returned.</p>
|
||
<p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised. If a
|
||
specific value for <em>name</em> is not supported by the host system, even if it is
|
||
included in <code class="docutils literal notranslate"><span class="pre">confstr_names</span></code>, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised with
|
||
<a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINVAL</span></code></a> for the error number.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.confstr_names">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">confstr_names</span></span><a class="headerlink" href="#os.confstr_names" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.confstr" title="os.confstr"><code class="xref py py-func docutils literal notranslate"><span class="pre">confstr()</span></code></a> to the integer values
|
||
defined for those names by the host operating system. This can be used to
|
||
determine the set of names known to the system.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.cpu_count">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">cpu_count</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.cpu_count" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the number of logical CPUs in the <strong>system</strong>. Returns <code class="docutils literal notranslate"><span class="pre">None</span></code> if
|
||
undetermined.</p>
|
||
<p>The <a class="reference internal" href="#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_cpu_count()</span></code></a> function can be used to get the number of
|
||
logical CPUs usable by the calling thread of the <strong>current process</strong>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.4.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.13: </span>If <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">cpu_count</span></code></a> is given or <span class="target" id="index-45"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_CPU_COUNT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_CPU_COUNT</span></code></a> is set,
|
||
<a class="reference internal" href="#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> returns the overridden value <em>n</em>.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getloadavg">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getloadavg</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.getloadavg" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return the number of processes in the system run queue averaged over the last
|
||
1, 5, and 15 minutes or raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if the load average was
|
||
unobtainable.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.process_cpu_count">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">process_cpu_count</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#os.process_cpu_count" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get the number of logical CPUs usable by the calling thread of the <strong>current
|
||
process</strong>. Returns <code class="docutils literal notranslate"><span class="pre">None</span></code> if undetermined. It can be less than
|
||
<a class="reference internal" href="#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> depending on the CPU affinity.</p>
|
||
<p>The <a class="reference internal" href="#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> function can be used to get the number of logical CPUs
|
||
in the <strong>system</strong>.</p>
|
||
<p>If <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">cpu_count</span></code></a> is given or <span class="target" id="index-46"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_CPU_COUNT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_CPU_COUNT</span></code></a> is set,
|
||
<a class="reference internal" href="#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_cpu_count()</span></code></a> returns the overridden value <em>n</em>.</p>
|
||
<p>See also the <a class="reference internal" href="#os.sched_getaffinity" title="os.sched_getaffinity"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getaffinity()</span></code></a> function.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.13.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.sysconf">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sysconf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.sysconf" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return integer-valued system configuration values. If the configuration value
|
||
specified by <em>name</em> isn’t defined, <code class="docutils literal notranslate"><span class="pre">-1</span></code> is returned. The comments regarding
|
||
the <em>name</em> parameter for <a class="reference internal" href="#os.confstr" title="os.confstr"><code class="xref py py-func docutils literal notranslate"><span class="pre">confstr()</span></code></a> apply here as well; the dictionary that
|
||
provides information on the known names is given by <code class="docutils literal notranslate"><span class="pre">sysconf_names</span></code>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.sysconf_names">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sysconf_names</span></span><a class="headerlink" href="#os.sysconf_names" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.sysconf" title="os.sysconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconf()</span></code></a> to the integer values
|
||
defined for those names by the host operating system. This can be used to
|
||
determine the set of names known to the system.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.11: </span>Add <code class="docutils literal notranslate"><span class="pre">'SC_MINSIGSTKSZ'</span></code> name.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>The following data values are used to support path manipulation operations. These
|
||
are defined for all platforms.</p>
|
||
<p>Higher-level operations on pathnames are defined in the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> module.</p>
|
||
<dl class="py data" id="index-47">
|
||
<dt class="sig sig-object py" id="os.curdir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">curdir</span></span><a class="headerlink" href="#os.curdir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The constant string used by the operating system to refer to the current
|
||
directory. This is <code class="docutils literal notranslate"><span class="pre">'.'</span></code> for Windows and POSIX. Also available via
|
||
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data" id="index-48">
|
||
<dt class="sig sig-object py" id="os.pardir">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pardir</span></span><a class="headerlink" href="#os.pardir" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The constant string used by the operating system to refer to the parent
|
||
directory. This is <code class="docutils literal notranslate"><span class="pre">'..'</span></code> for Windows and POSIX. Also available via
|
||
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data" id="index-50">
|
||
<span id="index-49"></span><dt class="sig sig-object py" id="os.sep">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">sep</span></span><a class="headerlink" href="#os.sep" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The character used by the operating system to separate pathname components.
|
||
This is <code class="docutils literal notranslate"><span class="pre">'/'</span></code> for POSIX and <code class="docutils literal notranslate"><span class="pre">'\\'</span></code> for Windows. Note that knowing this
|
||
is not sufficient to be able to parse or concatenate pathnames — use
|
||
<a class="reference internal" href="os.path.html#os.path.split" title="os.path.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.split()</span></code></a> and <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.join()</span></code></a> — but it is occasionally
|
||
useful. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data" id="index-51">
|
||
<dt class="sig sig-object py" id="os.altsep">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">altsep</span></span><a class="headerlink" href="#os.altsep" title="Link to this definition">¶</a></dt>
|
||
<dd><p>An alternative character used by the operating system to separate pathname
|
||
components, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if only one separator character exists. This is set to
|
||
<code class="docutils literal notranslate"><span class="pre">'/'</span></code> on Windows systems where <code class="docutils literal notranslate"><span class="pre">sep</span></code> is a backslash. Also available via
|
||
<a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data" id="index-52">
|
||
<dt class="sig sig-object py" id="os.extsep">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">extsep</span></span><a class="headerlink" href="#os.extsep" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The character which separates the base filename from the extension; for example,
|
||
the <code class="docutils literal notranslate"><span class="pre">'.'</span></code> in <code class="file docutils literal notranslate"><span class="pre">os.py</span></code>. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data" id="index-53">
|
||
<dt class="sig sig-object py" id="os.pathsep">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">pathsep</span></span><a class="headerlink" href="#os.pathsep" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The character conventionally used by the operating system to separate search
|
||
path components (as in <span class="target" id="index-54"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>), such as <code class="docutils literal notranslate"><span class="pre">':'</span></code> for POSIX or <code class="docutils literal notranslate"><span class="pre">';'</span></code> for
|
||
Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.defpath">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">defpath</span></span><a class="headerlink" href="#os.defpath" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The default search path used by <a class="reference internal" href="#os.execl" title="os.execl"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec*p*</span></code></a> and
|
||
<a class="reference internal" href="#os.spawnl" title="os.spawnl"><code class="xref py py-func docutils literal notranslate"><span class="pre">spawn*p*</span></code></a> if the environment doesn’t have a <code class="docutils literal notranslate"><span class="pre">'PATH'</span></code>
|
||
key. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.linesep">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">linesep</span></span><a class="headerlink" href="#os.linesep" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The string used to separate (or, rather, terminate) lines on the current
|
||
platform. This may be a single character, such as <code class="docutils literal notranslate"><span class="pre">'\n'</span></code> for POSIX, or
|
||
multiple characters, for example, <code class="docutils literal notranslate"><span class="pre">'\r\n'</span></code> for Windows. Do not use
|
||
<em>os.linesep</em> as a line terminator when writing files opened in text mode (the
|
||
default); use a single <code class="docutils literal notranslate"><span class="pre">'\n'</span></code> instead, on all platforms.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.devnull">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">devnull</span></span><a class="headerlink" href="#os.devnull" title="Link to this definition">¶</a></dt>
|
||
<dd><p>The file path of the null device. For example: <code class="docutils literal notranslate"><span class="pre">'/dev/null'</span></code> for
|
||
POSIX, <code class="docutils literal notranslate"><span class="pre">'nul'</span></code> for Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.RTLD_LAZY">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_LAZY</span></span><a class="headerlink" href="#os.RTLD_LAZY" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_NOW">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_NOW</span></span><a class="headerlink" href="#os.RTLD_NOW" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_GLOBAL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_GLOBAL</span></span><a class="headerlink" href="#os.RTLD_GLOBAL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_LOCAL">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_LOCAL</span></span><a class="headerlink" href="#os.RTLD_LOCAL" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_NODELETE">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_NODELETE</span></span><a class="headerlink" href="#os.RTLD_NODELETE" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_NOLOAD">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_NOLOAD</span></span><a class="headerlink" href="#os.RTLD_NOLOAD" title="Link to this definition">¶</a></dt>
|
||
<dt class="sig sig-object py" id="os.RTLD_DEEPBIND">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">RTLD_DEEPBIND</span></span><a class="headerlink" href="#os.RTLD_DEEPBIND" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Flags for use with the <a class="reference internal" href="sys.html#sys.setdlopenflags" title="sys.setdlopenflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">setdlopenflags()</span></code></a> and
|
||
<a class="reference internal" href="sys.html#sys.getdlopenflags" title="sys.getdlopenflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">getdlopenflags()</span></code></a> functions. See the Unix manual page
|
||
<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/dlopen(3)">dlopen(3)</a></em> for what the different flags mean.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.3.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="random-numbers">
|
||
<h2>Random numbers<a class="headerlink" href="#random-numbers" title="Link to this heading">¶</a></h2>
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.getrandom">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">getrandom</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.getrandom" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Get up to <em>size</em> random bytes. The function can return less bytes than
|
||
requested.</p>
|
||
<p>These bytes can be used to seed user-space random number generators or for
|
||
cryptographic purposes.</p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> relies on entropy gathered from device drivers and other
|
||
sources of environmental noise. Unnecessarily reading large quantities of
|
||
data will have a negative impact on other users of the <code class="docutils literal notranslate"><span class="pre">/dev/random</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code> devices.</p>
|
||
<p>The flags argument is a bit mask that can contain zero or more of the
|
||
following values ORed together: <a class="reference internal" href="#os.GRND_RANDOM" title="os.GRND_RANDOM"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.GRND_RANDOM</span></code></a> and
|
||
<a class="reference internal" href="#os.GRND_NONBLOCK" title="os.GRND_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">GRND_NONBLOCK</span></code></a>.</p>
|
||
<p>See also the <a class="reference external" href="https://man7.org/linux/man-pages/man2/getrandom.2.html">Linux getrandom() manual page</a>.</p>
|
||
<div class="availability docutils container">
|
||
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux >= 3.17.</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py function">
|
||
<dt class="sig sig-object py" id="os.urandom">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">urandom</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em><span class="sig-paren">)</span><a class="headerlink" href="#os.urandom" title="Link to this definition">¶</a></dt>
|
||
<dd><p>Return a bytestring of <em>size</em> random bytes suitable for cryptographic use.</p>
|
||
<p>This function returns random bytes from an OS-specific randomness source. The
|
||
returned data should be unpredictable enough for cryptographic applications,
|
||
though its exact quality depends on the OS implementation.</p>
|
||
<p>On Linux, if the <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall is available, it is used in
|
||
blocking mode: block until the system urandom entropy pool is initialized
|
||
(128 bits of entropy are collected by the kernel). See the <span class="target" id="index-55"></span><a class="pep reference external" href="https://peps.python.org/pep-0524/"><strong>PEP 524</strong></a> for
|
||
the rationale. On Linux, the <a class="reference internal" href="#os.getrandom" title="os.getrandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrandom()</span></code></a> function can be used to get
|
||
random bytes in non-blocking mode (using the <a class="reference internal" href="#os.GRND_NONBLOCK" title="os.GRND_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">GRND_NONBLOCK</span></code></a> flag) or
|
||
to poll until the system urandom entropy pool is initialized.</p>
|
||
<p>On a Unix-like system, random bytes are read from the <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code>
|
||
device. If the <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code> device is not available or not readable, the
|
||
<a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> exception is raised.</p>
|
||
<p>On Windows, it will use <code class="docutils literal notranslate"><span class="pre">BCryptGenRandom()</span></code>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p>The <a class="reference internal" href="secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> module provides higher level functions. For an
|
||
easy-to-use interface to the random number generator provided by your
|
||
platform, please see <a class="reference internal" href="random.html#random.SystemRandom" title="random.SystemRandom"><code class="xref py py-class docutils literal notranslate"><span class="pre">random.SystemRandom</span></code></a>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5: </span>On Linux 3.17 and newer, the <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall is now used
|
||
when available. On OpenBSD 5.6 and newer, the C <code class="docutils literal notranslate"><span class="pre">getentropy()</span></code>
|
||
function is now used. These functions avoid the usage of an internal file
|
||
descriptor.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.5.2: </span>On Linux, if the <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall blocks (the urandom entropy pool
|
||
is not initialized yet), fall back on reading <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code>.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.6: </span>On Linux, <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> is now used in blocking mode to increase the
|
||
security.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">Changed in version 3.11: </span>On Windows, <code class="docutils literal notranslate"><span class="pre">BCryptGenRandom()</span></code> is used instead of <code class="docutils literal notranslate"><span class="pre">CryptGenRandom()</span></code>
|
||
which is deprecated.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.GRND_NONBLOCK">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">GRND_NONBLOCK</span></span><a class="headerlink" href="#os.GRND_NONBLOCK" title="Link to this definition">¶</a></dt>
|
||
<dd><p>By default, when reading from <code class="docutils literal notranslate"><span class="pre">/dev/random</span></code>, <a class="reference internal" href="#os.getrandom" title="os.getrandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrandom()</span></code></a> blocks if
|
||
no random bytes are available, and when reading from <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code>, it blocks
|
||
if the entropy pool has not yet been initialized.</p>
|
||
<p>If the <a class="reference internal" href="#os.GRND_NONBLOCK" title="os.GRND_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">GRND_NONBLOCK</span></code></a> flag is set, then <a class="reference internal" href="#os.getrandom" title="os.getrandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">getrandom()</span></code></a> does not
|
||
block in these cases, but instead immediately raises <a class="reference internal" href="exceptions.html#BlockingIOError" title="BlockingIOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code></a>.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py data">
|
||
<dt class="sig sig-object py" id="os.GRND_RANDOM">
|
||
<span class="sig-prename descclassname"><span class="pre">os.</span></span><span class="sig-name descname"><span class="pre">GRND_RANDOM</span></span><a class="headerlink" href="#os.GRND_RANDOM" title="Link to this definition">¶</a></dt>
|
||
<dd><p>If this bit is set, then random bytes are drawn from the
|
||
<code class="docutils literal notranslate"><span class="pre">/dev/random</span></code> pool instead of the <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code> pool.</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">Added in version 3.6.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
<div>
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> — Miscellaneous operating system interfaces</a><ul>
|
||
<li><a class="reference internal" href="#file-names-command-line-arguments-and-environment-variables">File Names, Command Line Arguments, and Environment Variables</a></li>
|
||
<li><a class="reference internal" href="#python-utf-8-mode">Python UTF-8 Mode</a></li>
|
||
<li><a class="reference internal" href="#process-parameters">Process Parameters</a></li>
|
||
<li><a class="reference internal" href="#file-object-creation">File Object Creation</a></li>
|
||
<li><a class="reference internal" href="#file-descriptor-operations">File Descriptor Operations</a><ul>
|
||
<li><a class="reference internal" href="#querying-the-size-of-a-terminal">Querying the size of a terminal</a></li>
|
||
<li><a class="reference internal" href="#inheritance-of-file-descriptors">Inheritance of File Descriptors</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#files-and-directories">Files and Directories</a><ul>
|
||
<li><a class="reference internal" href="#timer-file-descriptors">Timer File Descriptors</a></li>
|
||
<li><a class="reference internal" href="#linux-extended-attributes">Linux extended attributes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#process-management">Process Management</a></li>
|
||
<li><a class="reference internal" href="#interface-to-the-scheduler">Interface to the scheduler</a></li>
|
||
<li><a class="reference internal" href="#miscellaneous-system-information">Miscellaneous System Information</a></li>
|
||
<li><a class="reference internal" href="#random-numbers">Random numbers</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="allos.html"
|
||
title="previous chapter">Generic Operating System Services</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="io.html"
|
||
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code> — Core tools for working with streams</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">Report a Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/main/Doc/library/os.rst"
|
||
rel="nofollow">Show Source
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div id="sidebarbutton" title="Collapse sidebar">
|
||
<span>«</span>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="io.html" title="io — Core tools for working with streams"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="allos.html" title="Generic Operating System Services"
|
||
>previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.3 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="allos.html" >Generic Operating System Services</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code> — Miscellaneous operating system interfaces</a></li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
<li class="right">
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label> |</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
©
|
||
<a href="../copyright.html">
|
||
|
||
Copyright
|
||
|
||
</a>
|
||
2001-2025, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
See <a href="/license.html">History and License</a> for more information.<br />
|
||
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
Last updated on Apr 08, 2025 (14:33 UTC).
|
||
|
||
<a href="/bugs.html">Found a bug</a>?
|
||
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |