Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
mmap.html910 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="mmap — Memory-mapped file support" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/mmap.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. Memory-mapped file objects behave like both bytearray and like ..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_mmap_1374523b.png" />15<meta property="og:image:alt" content="Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. Memory-mapped file objects behave like both bytearray and like ..." />16<meta name="description" content="Availability: not WASI. This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information. Memory-mapped file objects behave like both bytearray and like ..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>mmap — Memory-mapped file support &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="Internet Data Handling" href="netdata.html" />43    <link rel="prev" title="signal — Set handlers for asynchronous events" href="signal.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/mmap.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <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>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code> — Memory-mapped file support</a><ul>108<li><a class="reference internal" href="#madv-constants">MADV_* Constants</a></li>109<li><a class="reference internal" href="#map-constants">MAP_* Constants</a></li>110<li><a class="reference internal" href="#ms-constants">MS_* Constants</a></li>111</ul>112</li>113</ul>114 115  </div>116  <div>117    <h4>Previous topic</h4>118    <p class="topless"><a href="signal.html"119                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code> — Set handlers for asynchronous events</a></p>120  </div>121  <div>122    <h4>Next topic</h4>123    <p class="topless"><a href="netdata.html"124                          title="next chapter">Internet Data Handling</a></p>125  </div>126  <script>127    document.addEventListener('DOMContentLoaded', () => {128        const title = document.querySelector('meta[property="og:title"]').content;129        const elements = document.querySelectorAll('.improvepage');130        const pageurl = window.location.href.split('?')[0];131        elements.forEach(element => {132            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));133            url.searchParams.set('pagetitle', title);134            url.searchParams.set('pageurl', pageurl);135            url.searchParams.set('pagesource', "library/mmap.rst");136            element.href = url.toString();137        });138    });139  </script>140  <div role="note" aria-label="source link">141    <h3>This page</h3>142    <ul class="this-page-menu">143      <li><a href="../bugs.html">Report a bug</a></li>144      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>145      <li>146        <a href="https://github.com/python/cpython/blob/main/Doc/library/mmap.rst?plain=1"147            rel="nofollow">Show source148        </a>149      </li>150      151    </ul>152  </div>153        </nav>154    </div>155</div>156 157  158    <div class="related" role="navigation" aria-label="Related">159      <h3>Navigation</h3>160      <ul>161        <li class="right" style="margin-right: 10px">162          <a href="../genindex.html" title="General Index"163             accesskey="I">index</a></li>164        <li class="right" >165          <a href="../py-modindex.html" title="Python Module Index"166             >modules</a> |</li>167        <li class="right" >168          <a href="netdata.html" title="Internet Data Handling"169             accesskey="N">next</a> |</li>170        <li class="right" >171          <a href="signal.html" title="signal — Set handlers for asynchronous events"172             accesskey="P">previous</a> |</li>173 174          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>175          <li><a href="https://www.python.org/">Python</a> &#187;</li>176          <li class="switchers">177            <div class="language_switcher_placeholder"></div>178            <div class="version_switcher_placeholder"></div>179          </li>180          <li>181              182          </li>183    <li id="cpython-language-and-version">184      <a href="../index.html">3.15.0a6 Documentation</a> &#187;185    </li>186 187          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>188          <li class="nav-item nav-item-2"><a href="ipc.html" accesskey="U">Networking and Interprocess Communication</a> &#187;</li>189        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code> — Memory-mapped file support</a></li>190                <li class="right">191                    192 193    <div class="inline-search" role="search">194        <form class="inline-search" action="../search.html" method="get">195          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">196          <input type="submit" value="Go">197        </form>198    </div>199                     |200                </li>201            <li class="right">202<label class="theme-selector-label">203    Theme204    <select class="theme-selector" oninput="activateTheme(this.value)">205        <option value="auto" selected>Auto</option>206        <option value="light">Light</option>207        <option value="dark">Dark</option>208    </select>209</label> |</li>210            211      </ul>212    </div>    213 214    <div class="document">215      <div class="documentwrapper">216        <div class="bodywrapper">217          <div class="body" role="main">218            219  <section id="module-mmap">220<span id="mmap-memory-mapped-file-support"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code> — Memory-mapped file support<a class="headerlink" href="#module-mmap" title="Link to this heading">¶</a></h1>221<hr class="docutils" />222<div class="availability docutils container">223<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>224<p>This module does not work or is not available on WebAssembly. See225<a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>226</div>227<p>Memory-mapped file objects behave like both <a class="reference internal" href="stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> and like228<a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file objects</span></a>.  You can use mmap objects in most places229where <code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code> are expected; for example, you can use the <a class="reference internal" href="re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>230module to search through a memory-mapped file.  You can also change a single231byte by doing <code class="docutils literal notranslate"><span class="pre">obj[index]</span> <span class="pre">=</span> <span class="pre">97</span></code>, or change a subsequence by assigning to a232slice: <code class="docutils literal notranslate"><span class="pre">obj[i1:i2]</span> <span class="pre">=</span> <span class="pre">b'...'</span></code>.  You can also read and write data starting at233the current file position, and <code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code> through the file to different positions.</p>234<p>A memory-mapped file is created by the <a class="reference internal" href="#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> constructor, which is235different on Unix and on Windows.  In either case you must provide a file236descriptor for a file opened for update. If you wish to map an existing Python237file object, use its <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 to obtain the correct value for the238<em>fileno</em> parameter.  Otherwise, you can open the file using the239<a class="reference internal" href="os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> function, which returns a file descriptor directly (the file240still needs to be closed when done).</p>241<div class="admonition note">242<p class="admonition-title">Note</p>243<p>If you want to create a memory-mapping for a writable, buffered file, you244should <a class="reference internal" href="io.html#io.IOBase.flush" title="io.IOBase.flush"><code class="xref py py-func docutils literal notranslate"><span class="pre">flush()</span></code></a> the file first.  This is necessary to ensure245that local modifications to the buffers are actually available to the246mapping.</p>247</div>248<p>For both the Unix and Windows versions of the constructor, <em>access</em> may be249specified as an optional keyword parameter. <em>access</em> accepts one of four250values: <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_WRITE</span></code>, or <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_COPY</span></code> to251specify read-only, write-through or copy-on-write memory respectively, or252<code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_DEFAULT</span></code> to defer to <em>prot</em>.  <em>access</em> can be used on both Unix253and Windows.  If <em>access</em> is not specified, Windows mmap returns a254write-through mapping.  The initial memory values for all three access types255are taken from the specified file.  Assignment to an <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code>256memory map raises a <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> exception.  Assignment to an257<code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_WRITE</span></code> memory map affects both memory and the underlying file.258Assignment to an <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_COPY</span></code> memory map affects memory but does not259update the underlying file.</p>260<div class="versionchanged">261<p><span class="versionmodified changed">Changed in version 3.7: </span>Added <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_DEFAULT</span></code> constant.</p>262</div>263<p>To map anonymous memory, -1 should be passed as the fileno along with the length.</p>264<dl class="py class">265<dt class="sig sig-object py" id="mmap.mmap">266<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">mmap.</span></span><span class="sig-name descname"><span class="pre">mmap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fileno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tagname</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">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">ACCESS_DEFAULT</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</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">trackfd</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="#mmap.mmap" title="Link to this definition">¶</a></dt>267<dd><p><strong>(Windows version)</strong> Maps <em>length</em> bytes from the file specified by the268file descriptor <em>fileno</em>, and creates a mmap object.  If <em>length</em> is larger269than the current size of the file, the file is extended to contain <em>length</em>270bytes.  If <em>length</em> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, the maximum length of the map is the current271size of the file, except that if the file is empty Windows raises an272exception (you cannot create an empty mapping on Windows).</p>273<p><em>tagname</em>, if specified and not <code class="docutils literal notranslate"><span class="pre">None</span></code>, is a string giving a tag name for274the mapping.  Windows allows you to have many different mappings against275the same file.  If you specify the name of an existing tag, that tag is276opened, otherwise a new tag of this name is created.  If this parameter is277omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, the mapping is created without a name.  Avoiding the278use of the <em>tagname</em> parameter will assist in keeping your code portable279between Unix and Windows.</p>280<p><em>offset</em> may be specified as a non-negative integer offset. mmap references281will be relative to the offset from the beginning of the file. <em>offset</em>282defaults to 0.  <em>offset</em> must be a multiple of the <code class="xref py py-const docutils literal notranslate"><span class="pre">ALLOCATIONGRANULARITY</span></code>.</p>283<p>If <em>trackfd</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the file handle corresponding to <em>fileno</em> will284not be duplicated, and the resulting <code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code> object will not285be associated with the map’s underlying file.286This means that the <a class="reference internal" href="#mmap.mmap.size" title="mmap.mmap.size"><code class="xref py py-meth docutils literal notranslate"><span class="pre">size()</span></code></a> and <a class="reference internal" href="#mmap.mmap.resize" title="mmap.mmap.resize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">resize()</span></code></a>287methods will fail.288This mode is useful to limit the number of open file handles.289The original file can be renamed (but not deleted) after closing <em>fileno</em>.</p>290<div class="versionchanged">291<p><span class="versionmodified changed">Changed in version 3.15: </span>The <em>trackfd</em> parameter was added.</p>292</div>293<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">mmap.__new__</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">fileno</span></code>, <code class="docutils literal notranslate"><span class="pre">length</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>, <code class="docutils literal notranslate"><span class="pre">offset</span></code>.</p>294</dd></dl>295 296<dl class="py class">297<dt class="sig sig-object py">298<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">mmap.</span></span><span class="sig-name descname"><span class="pre">mmap</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fileno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</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">MAP_SHARED</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prot</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">PROT_WRITE</span> <span class="pre">|</span> <span class="pre">PROT_READ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">ACCESS_DEFAULT</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">offset</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">trackfd</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></dt>299<dd><p><strong>(Unix version)</strong> Maps <em>length</em> bytes from the file specified by the file300descriptor <em>fileno</em>, and returns a mmap object.  If <em>length</em> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, the301maximum length of the map will be the current size of the file when302<a class="reference internal" href="#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> is called.</p>303<p><em>flags</em> specifies the nature of the mapping. <a class="reference internal" href="#mmap.MAP_PRIVATE" title="mmap.MAP_PRIVATE"><code class="xref py py-const docutils literal notranslate"><span class="pre">MAP_PRIVATE</span></code></a> creates a304private copy-on-write mapping, so changes to the contents of the mmap305object will be private to this process, and <a class="reference internal" href="#mmap.MAP_SHARED" title="mmap.MAP_SHARED"><code class="xref py py-const docutils literal notranslate"><span class="pre">MAP_SHARED</span></code></a> creates a306mapping that’s shared with all other processes mapping the same areas of307the file.  The default value is <code class="xref py py-const docutils literal notranslate"><span class="pre">MAP_SHARED</span></code>. Some systems have308additional possible flags with the full list specified in309<a class="reference internal" href="#map-constants"><span class="std std-ref">MAP_* constants</span></a>.</p>310<p><em>prot</em>, if specified, gives the desired memory protection; the two most311useful values are <code class="xref py py-const docutils literal notranslate"><span class="pre">PROT_READ</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">PROT_WRITE</span></code>, to specify312that the pages may be read or written.  <em>prot</em> defaults to313<code class="xref py py-const docutils literal notranslate"><span class="pre">PROT_READ</span> <span class="pre">|</span> <span class="pre">PROT_WRITE</span></code>.</p>314<p><em>access</em> may be specified in lieu of <em>flags</em> and <em>prot</em> as an optional315keyword parameter.  It is an error to specify both <em>flags</em>, <em>prot</em> and316<em>access</em>.  See the description of <em>access</em> above for information on how to317use this parameter.</p>318<p><em>offset</em> may be specified as a non-negative integer offset. mmap references319will be relative to the offset from the beginning of the file. <em>offset</em>320defaults to 0. <em>offset</em> must be a multiple of <code class="xref py py-const docutils literal notranslate"><span class="pre">ALLOCATIONGRANULARITY</span></code>321which is equal to <code class="xref py py-const docutils literal notranslate"><span class="pre">PAGESIZE</span></code> on Unix systems.</p>322<p>If <em>trackfd</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the file descriptor specified by <em>fileno</em> will323not be duplicated, and the resulting <code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code> object will not324be associated with the map’s underlying file.325This means that the <a class="reference internal" href="#mmap.mmap.size" title="mmap.mmap.size"><code class="xref py py-meth docutils literal notranslate"><span class="pre">size()</span></code></a> and <a class="reference internal" href="#mmap.mmap.resize" title="mmap.mmap.resize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">resize()</span></code></a>326methods will fail.327This mode is useful to limit the number of open file descriptors.</p>328<p>To ensure validity of the created memory mapping the file specified329by the descriptor <em>fileno</em> is internally automatically synchronized330with the physical backing store on macOS.</p>331<div class="versionchanged">332<p><span class="versionmodified changed">Changed in version 3.13: </span>The <em>trackfd</em> parameter was added.</p>333</div>334<p>This example shows a simple way of using <a class="reference internal" href="#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a>:</p>335<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">mmap</span>336 337<span class="c1"># write a simple example file</span>338<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;hello.txt&quot;</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>339    <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;Hello Python!</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>340 341<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;hello.txt&quot;</span><span class="p">,</span> <span class="s2">&quot;r+b&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>342    <span class="c1"># memory-map the file, size 0 means whole file</span>343    <span class="n">mm</span> <span class="o">=</span> <span class="n">mmap</span><span class="o">.</span><span class="n">mmap</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="mi">0</span><span class="p">)</span>344    <span class="c1"># read content via standard file methods</span>345    <span class="nb">print</span><span class="p">(</span><span class="n">mm</span><span class="o">.</span><span class="n">readline</span><span class="p">())</span>  <span class="c1"># prints b&quot;Hello Python!\n&quot;</span>346    <span class="c1"># read content via slice notation</span>347    <span class="nb">print</span><span class="p">(</span><span class="n">mm</span><span class="p">[:</span><span class="mi">5</span><span class="p">])</span>  <span class="c1"># prints b&quot;Hello&quot;</span>348    <span class="c1"># update content using slice notation;</span>349    <span class="c1"># note that new content must have same size</span>350    <span class="n">mm</span><span class="p">[</span><span class="mi">6</span><span class="p">:]</span> <span class="o">=</span> <span class="sa">b</span><span class="s2">&quot; world!</span><span class="se">\n</span><span class="s2">&quot;</span>351    <span class="c1"># ... and read again using standard file methods</span>352    <span class="n">mm</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>353    <span class="nb">print</span><span class="p">(</span><span class="n">mm</span><span class="o">.</span><span class="n">readline</span><span class="p">())</span>  <span class="c1"># prints b&quot;Hello  world!\n&quot;</span>354    <span class="c1"># close the map</span>355    <span class="n">mm</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>356</pre></div>357</div>358<p><a class="reference internal" href="#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> can also be used as a context manager 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>359statement:</p>360<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">mmap</span>361 362<span class="k">with</span> <span class="n">mmap</span><span class="o">.</span><span class="n">mmap</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">13</span><span class="p">)</span> <span class="k">as</span> <span class="n">mm</span><span class="p">:</span>363    <span class="n">mm</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;Hello world!&quot;</span><span class="p">)</span>364</pre></div>365</div>366<div class="versionadded">367<p><span class="versionmodified added">Added in version 3.2: </span>Context manager support.</p>368</div>369<p>The next example demonstrates how to create an anonymous map and exchange370data between the parent and child processes:</p>371<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">mmap</span>372<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>373 374<span class="n">mm</span> <span class="o">=</span> <span class="n">mmap</span><span class="o">.</span><span class="n">mmap</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">13</span><span class="p">)</span>375<span class="n">mm</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;Hello world!&quot;</span><span class="p">)</span>376 377<span class="n">pid</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">fork</span><span class="p">()</span>378 379<span class="k">if</span> <span class="n">pid</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>  <span class="c1"># In a child process</span>380    <span class="n">mm</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>381    <span class="nb">print</span><span class="p">(</span><span class="n">mm</span><span class="o">.</span><span class="n">readline</span><span class="p">())</span>382 383    <span class="n">mm</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>384</pre></div>385</div>386<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">mmap.__new__</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">fileno</span></code>, <code class="docutils literal notranslate"><span class="pre">length</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>, <code class="docutils literal notranslate"><span class="pre">offset</span></code>.</p>387<p>Memory-mapped file objects support the following methods:</p>388<dl class="py method">389<dt class="sig sig-object py" id="mmap.mmap.close">390<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="#mmap.mmap.close" title="Link to this definition">¶</a></dt>391<dd><p>Closes the mmap. Subsequent calls to other methods of the object will392result in a ValueError exception being raised. This will not close393the open file.</p>394</dd></dl>395 396<dl class="py attribute">397<dt class="sig sig-object py" id="mmap.mmap.closed">398<span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#mmap.mmap.closed" title="Link to this definition">¶</a></dt>399<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the file is closed.</p>400<div class="versionadded">401<p><span class="versionmodified added">Added in version 3.2.</span></p>402</div>403</dd></dl>404 405<dl class="py method">406<dt class="sig sig-object py" id="mmap.mmap.find">407<span class="sig-name descname"><span class="pre">find</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sub</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">start</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">end</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.find" title="Link to this definition">¶</a></dt>408<dd><p>Returns the lowest index in the object where the subsequence <em>sub</em> is409found, such that <em>sub</em> is contained in the range [<em>start</em>, <em>end</em>].410Optional arguments <em>start</em> and <em>end</em> are interpreted as in slice notation.411Returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>412<div class="versionchanged">413<p><span class="versionmodified changed">Changed in version 3.5: </span>Writable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is now accepted.</p>414</div>415</dd></dl>416 417<dl class="py method">418<dt class="sig sig-object py" id="mmap.mmap.flush">419<span class="sig-name descname"><span class="pre">flush</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">offset</span></span></em>, <span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <span class="optional">]</span><span class="optional">]</span><em class="sig-param"><span class="n"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flags=MS_SYNC</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.flush" title="Link to this definition">¶</a></dt>420<dd><p>Flushes changes made to the in-memory copy of a file back to disk. Without421use of this call there is no guarantee that changes are written back before422the object is destroyed.  If <em>offset</em> and <em>size</em> are specified, only423changes to the given range of bytes will be flushed to disk; otherwise, the424whole extent of the mapping is flushed.  <em>offset</em> must be a multiple of the425<code class="xref py py-const docutils literal notranslate"><span class="pre">PAGESIZE</span></code> or <code class="xref py py-const docutils literal notranslate"><span class="pre">ALLOCATIONGRANULARITY</span></code>.</p>426<p>The <em>flags</em> parameter specifies the synchronization behavior.427<em>flags</em> must be one of the <a class="reference internal" href="#ms-constants"><span class="std std-ref">MS_* constants</span></a> available428on the system.</p>429<p>On Windows, the <em>flags</em> parameter is ignored.</p>430<p><code class="docutils literal notranslate"><span class="pre">None</span></code> is returned to indicate success.  An exception is raised when the431call failed.</p>432<div class="versionchanged">433<p><span class="versionmodified changed">Changed in version 3.8: </span>Previously, a nonzero value was returned on success; zero was returned434on error under Windows.  A zero value was returned on success; an435exception was raised on error under Unix.</p>436</div>437<div class="versionchanged">438<p><span class="versionmodified changed">Changed in version 3.15: </span>Allow specifying <em>offset</em> without <em>size</em>. Previously, both <em>offset</em>439and <em>size</em> parameters were required together. Now <em>offset</em> can be440specified alone, and the flush operation will extend from <em>offset</em>441to the end of the mmap.</p>442</div>443<div class="versionchanged">444<p><span class="versionmodified changed">Changed in version 3.15: </span>Added <em>flags</em> parameter to control synchronization behavior.</p>445</div>446</dd></dl>447 448<dl class="py method">449<dt class="sig sig-object py" id="mmap.mmap.madvise">450<span class="sig-name descname"><span class="pre">madvise</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">option</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">start</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.madvise" title="Link to this definition">¶</a></dt>451<dd><p>Send advice <em>option</em> to the kernel about the memory region beginning at452<em>start</em> and extending <em>length</em> bytes.  <em>option</em> must be one of the453<a class="reference internal" href="#madvise-constants"><span class="std std-ref">MADV_* constants</span></a> available on the system.  If454<em>start</em> and <em>length</em> are omitted, the entire mapping is spanned.  On455some systems (including Linux), <em>start</em> must be a multiple of the456<code class="xref py py-const docutils literal notranslate"><span class="pre">PAGESIZE</span></code>.</p>457<p>Availability: Systems with the <code class="docutils literal notranslate"><span class="pre">madvise()</span></code> system call.</p>458<div class="versionadded">459<p><span class="versionmodified added">Added in version 3.8.</span></p>460</div>461</dd></dl>462 463<dl class="py method">464<dt class="sig sig-object py" id="mmap.mmap.move">465<span class="sig-name descname"><span class="pre">move</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dest</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">src</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="#mmap.mmap.move" title="Link to this definition">¶</a></dt>466<dd><p>Copy the <em>count</em> bytes starting at offset <em>src</em> to the destination index467<em>dest</em>.  If the mmap was created with <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code>, then calls to468move will raise a <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> exception.</p>469</dd></dl>470 471<dl class="py method">472<dt class="sig sig-object py" id="mmap.mmap.read">473<span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.read" title="Link to this definition">¶</a></dt>474<dd><p>Return a <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> containing up to <em>n</em> bytes starting from the475current file position. If the argument is omitted, <code class="docutils literal notranslate"><span class="pre">None</span></code> or negative,476return all bytes from the current file position to the end of the477mapping. The file position is updated to point after the bytes that were478returned.</p>479<div class="versionchanged">480<p><span class="versionmodified changed">Changed in version 3.3: </span>Argument can be omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>481</div>482</dd></dl>483 484<dl class="py method">485<dt class="sig sig-object py" id="mmap.mmap.read_byte">486<span class="sig-name descname"><span class="pre">read_byte</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.read_byte" title="Link to this definition">¶</a></dt>487<dd><p>Returns a byte at the current file position as an integer, and advances488the file position by 1.</p>489</dd></dl>490 491<dl class="py method">492<dt class="sig sig-object py" id="mmap.mmap.readline">493<span class="sig-name descname"><span class="pre">readline</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.readline" title="Link to this definition">¶</a></dt>494<dd><p>Returns a single line, starting at the current file position and up to the495next newline. The file position is updated to point after the bytes that were496returned.</p>497</dd></dl>498 499<dl class="py method">500<dt class="sig sig-object py" id="mmap.mmap.resize">501<span class="sig-name descname"><span class="pre">resize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">newsize</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.resize" title="Link to this definition">¶</a></dt>502<dd><p>Resizes the map and the underlying file, if any.</p>503<p>Resizing a map created with <em>access</em> of <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code> or504<code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_COPY</span></code>, will raise a <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> exception.505Resizing a map created with <em>trackfd</em> set to <code class="docutils literal notranslate"><span class="pre">False</span></code>,506will 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> exception.</p>507<p><strong>On Windows</strong>: Resizing the map will raise 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> if there are other508maps against the same named file. Resizing an anonymous map (ie against the509pagefile) will silently create a new map with the original data copied over510up to the length of the new size.</p>511<p>Availability: Windows and systems with the <code class="docutils literal notranslate"><span class="pre">mremap()</span></code> system call.</p>512<div class="versionchanged">513<p><span class="versionmodified changed">Changed in version 3.11: </span>Correctly fails if attempting to resize when another map is held514Allows resize against an anonymous map on Windows</p>515</div>516</dd></dl>517 518<dl class="py method">519<dt class="sig sig-object py" id="mmap.mmap.rfind">520<span class="sig-name descname"><span class="pre">rfind</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sub</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">start</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">end</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.rfind" title="Link to this definition">¶</a></dt>521<dd><p>Returns the highest index in the object where the subsequence <em>sub</em> is522found, such that <em>sub</em> is contained in the range [<em>start</em>, <em>end</em>].523Optional arguments <em>start</em> and <em>end</em> are interpreted as in slice notation.524Returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>525<div class="versionchanged">526<p><span class="versionmodified changed">Changed in version 3.5: </span>Writable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is now accepted.</p>527</div>528</dd></dl>529 530<dl class="py method">531<dt class="sig sig-object py" id="mmap.mmap.seek">532<span class="sig-name descname"><span class="pre">seek</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">whence</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.seek" title="Link to this definition">¶</a></dt>533<dd><p>Set the file’s current position.  <em>whence</em> argument is optional and534defaults to <code class="docutils literal notranslate"><span class="pre">os.SEEK_SET</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> (absolute file positioning); other535values are <code class="docutils literal notranslate"><span class="pre">os.SEEK_CUR</span></code> or <code class="docutils literal notranslate"><span class="pre">1</span></code> (seek relative to the current536position) and <code class="docutils literal notranslate"><span class="pre">os.SEEK_END</span></code> or <code class="docutils literal notranslate"><span class="pre">2</span></code> (seek relative to the file’s end).</p>537<div class="versionchanged">538<p><span class="versionmodified changed">Changed in version 3.13: </span>Return the new absolute position instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>539</div>540</dd></dl>541 542<dl class="py method">543<dt class="sig sig-object py" id="mmap.mmap.seekable">544<span class="sig-name descname"><span class="pre">seekable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.seekable" title="Link to this definition">¶</a></dt>545<dd><p>Return whether the file supports seeking, and the return value is always <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>546<div class="versionadded">547<p><span class="versionmodified added">Added in version 3.13.</span></p>548</div>549</dd></dl>550 551<dl class="py method">552<dt class="sig sig-object py" id="mmap.mmap.set_name">553<span class="sig-name descname"><span class="pre">set_name</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="#mmap.mmap.set_name" title="Link to this definition">¶</a></dt>554<dd><p>Annotate the memory mapping with the given <em>name</em> for easier identification555in <code class="docutils literal notranslate"><span class="pre">/proc/&lt;pid&gt;/maps</span></code> if the kernel supports the feature and <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">dev</span></code></a> is passed556to Python or if Python is built in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug mode</span></a>.557The length of <em>name</em> must not exceed 67 bytes including the <code class="docutils literal notranslate"><span class="pre">'\0'</span></code> terminator.</p>558<div class="availability docutils container">559<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 5.17 (kernel built with <code class="docutils literal notranslate"><span class="pre">CONFIG_ANON_VMA_NAME</span></code> option)</p>560</div>561<div class="versionadded">562<p><span class="versionmodified added">Added in version 3.15.</span></p>563</div>564</dd></dl>565 566<dl class="py method">567<dt class="sig sig-object py" id="mmap.mmap.size">568<span class="sig-name descname"><span class="pre">size</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.size" title="Link to this definition">¶</a></dt>569<dd><p>Return the length of the file, which can be larger than the size of the570memory-mapped area.571For an anonymous mapping, return its size.</p>572<div class="versionchanged">573<p><span class="versionmodified changed">Changed in version 3.15: </span>Anonymous mappings are now supported on Unix.</p>574</div>575</dd></dl>576 577<dl class="py method">578<dt class="sig sig-object py" id="mmap.mmap.tell">579<span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.tell" title="Link to this definition">¶</a></dt>580<dd><p>Returns the current position of the file pointer.</p>581</dd></dl>582 583<dl class="py method">584<dt class="sig sig-object py" id="mmap.mmap.write">585<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">bytes</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.write" title="Link to this definition">¶</a></dt>586<dd><p>Write the bytes in <em>bytes</em> into memory at the current position of the587file pointer and return the number of bytes written (never less than588<code class="docutils literal notranslate"><span class="pre">len(bytes)</span></code>, since if the write fails, 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> will be589raised).  The file position is updated to point after the bytes that590were written.  If the mmap was created with <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code>, then591writing to it will raise a <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> exception.</p>592<div class="versionchanged">593<p><span class="versionmodified changed">Changed in version 3.5: </span>Writable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is now accepted.</p>594</div>595<div class="versionchanged">596<p><span class="versionmodified changed">Changed in version 3.6: </span>The number of bytes written is now returned.</p>597</div>598</dd></dl>599 600<dl class="py method">601<dt class="sig sig-object py" id="mmap.mmap.write_byte">602<span class="sig-name descname"><span class="pre">write_byte</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">byte</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#mmap.mmap.write_byte" title="Link to this definition">¶</a></dt>603<dd><p>Write the integer <em>byte</em> into memory at the current604position of the file pointer; the file position is advanced by <code class="docutils literal notranslate"><span class="pre">1</span></code>. If605the mmap was created with <code class="xref py py-const docutils literal notranslate"><span class="pre">ACCESS_READ</span></code>, then writing to it will606raise a <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> exception.</p>607</dd></dl>608 609</dd></dl>610 611<section id="madv-constants">612<span id="madvise-constants"></span><h2>MADV_* Constants<a class="headerlink" href="#madv-constants" title="Link to this heading">¶</a></h2>613<dl class="py data">614<dt class="sig sig-object py" id="mmap.MADV_NORMAL">615<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_NORMAL</span></span><a class="headerlink" href="#mmap.MADV_NORMAL" title="Link to this definition">¶</a></dt>616<dt class="sig sig-object py" id="mmap.MADV_RANDOM">617<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_RANDOM</span></span><a class="headerlink" href="#mmap.MADV_RANDOM" title="Link to this definition">¶</a></dt>618<dt class="sig sig-object py" id="mmap.MADV_SEQUENTIAL">619<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_SEQUENTIAL</span></span><a class="headerlink" href="#mmap.MADV_SEQUENTIAL" title="Link to this definition">¶</a></dt>620<dt class="sig sig-object py" id="mmap.MADV_WILLNEED">621<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_WILLNEED</span></span><a class="headerlink" href="#mmap.MADV_WILLNEED" title="Link to this definition">¶</a></dt>622<dt class="sig sig-object py" id="mmap.MADV_DONTNEED">623<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_DONTNEED</span></span><a class="headerlink" href="#mmap.MADV_DONTNEED" title="Link to this definition">¶</a></dt>624<dt class="sig sig-object py" id="mmap.MADV_REMOVE">625<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_REMOVE</span></span><a class="headerlink" href="#mmap.MADV_REMOVE" title="Link to this definition">¶</a></dt>626<dt class="sig sig-object py" id="mmap.MADV_DONTFORK">627<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_DONTFORK</span></span><a class="headerlink" href="#mmap.MADV_DONTFORK" title="Link to this definition">¶</a></dt>628<dt class="sig sig-object py" id="mmap.MADV_DOFORK">629<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_DOFORK</span></span><a class="headerlink" href="#mmap.MADV_DOFORK" title="Link to this definition">¶</a></dt>630<dt class="sig sig-object py" id="mmap.MADV_HWPOISON">631<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_HWPOISON</span></span><a class="headerlink" href="#mmap.MADV_HWPOISON" title="Link to this definition">¶</a></dt>632<dt class="sig sig-object py" id="mmap.MADV_MERGEABLE">633<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_MERGEABLE</span></span><a class="headerlink" href="#mmap.MADV_MERGEABLE" title="Link to this definition">¶</a></dt>634<dt class="sig sig-object py" id="mmap.MADV_UNMERGEABLE">635<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_UNMERGEABLE</span></span><a class="headerlink" href="#mmap.MADV_UNMERGEABLE" title="Link to this definition">¶</a></dt>636<dt class="sig sig-object py" id="mmap.MADV_SOFT_OFFLINE">637<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_SOFT_OFFLINE</span></span><a class="headerlink" href="#mmap.MADV_SOFT_OFFLINE" title="Link to this definition">¶</a></dt>638<dt class="sig sig-object py" id="mmap.MADV_HUGEPAGE">639<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_HUGEPAGE</span></span><a class="headerlink" href="#mmap.MADV_HUGEPAGE" title="Link to this definition">¶</a></dt>640<dt class="sig sig-object py" id="mmap.MADV_NOHUGEPAGE">641<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_NOHUGEPAGE</span></span><a class="headerlink" href="#mmap.MADV_NOHUGEPAGE" title="Link to this definition">¶</a></dt>642<dt class="sig sig-object py" id="mmap.MADV_DONTDUMP">643<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_DONTDUMP</span></span><a class="headerlink" href="#mmap.MADV_DONTDUMP" title="Link to this definition">¶</a></dt>644<dt class="sig sig-object py" id="mmap.MADV_DODUMP">645<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_DODUMP</span></span><a class="headerlink" href="#mmap.MADV_DODUMP" title="Link to this definition">¶</a></dt>646<dt class="sig sig-object py" id="mmap.MADV_FREE">647<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_FREE</span></span><a class="headerlink" href="#mmap.MADV_FREE" title="Link to this definition">¶</a></dt>648<dt class="sig sig-object py" id="mmap.MADV_NOSYNC">649<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_NOSYNC</span></span><a class="headerlink" href="#mmap.MADV_NOSYNC" title="Link to this definition">¶</a></dt>650<dt class="sig sig-object py" id="mmap.MADV_AUTOSYNC">651<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_AUTOSYNC</span></span><a class="headerlink" href="#mmap.MADV_AUTOSYNC" title="Link to this definition">¶</a></dt>652<dt class="sig sig-object py" id="mmap.MADV_NOCORE">653<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_NOCORE</span></span><a class="headerlink" href="#mmap.MADV_NOCORE" title="Link to this definition">¶</a></dt>654<dt class="sig sig-object py" id="mmap.MADV_CORE">655<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_CORE</span></span><a class="headerlink" href="#mmap.MADV_CORE" title="Link to this definition">¶</a></dt>656<dt class="sig sig-object py" id="mmap.MADV_PROTECT">657<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_PROTECT</span></span><a class="headerlink" href="#mmap.MADV_PROTECT" title="Link to this definition">¶</a></dt>658<dt class="sig sig-object py" id="mmap.MADV_FREE_REUSABLE">659<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_FREE_REUSABLE</span></span><a class="headerlink" href="#mmap.MADV_FREE_REUSABLE" title="Link to this definition">¶</a></dt>660<dt class="sig sig-object py" id="mmap.MADV_FREE_REUSE">661<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MADV_FREE_REUSE</span></span><a class="headerlink" href="#mmap.MADV_FREE_REUSE" title="Link to this definition">¶</a></dt>662<dd><p>These options can be passed to <a class="reference internal" href="#mmap.mmap.madvise" title="mmap.mmap.madvise"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mmap.madvise()</span></code></a>.  Not every option will663be present on every system.</p>664<p>Availability: Systems with the madvise() system call.</p>665<div class="versionadded">666<p><span class="versionmodified added">Added in version 3.8.</span></p>667</div>668</dd></dl>669 670</section>671<section id="map-constants">672<span id="id1"></span><h2>MAP_* Constants<a class="headerlink" href="#map-constants" title="Link to this heading">¶</a></h2>673<dl class="py data">674<dt class="sig sig-object py" id="mmap.MAP_SHARED">675<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_SHARED</span></span><a class="headerlink" href="#mmap.MAP_SHARED" title="Link to this definition">¶</a></dt>676<dt class="sig sig-object py" id="mmap.MAP_PRIVATE">677<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_PRIVATE</span></span><a class="headerlink" href="#mmap.MAP_PRIVATE" title="Link to this definition">¶</a></dt>678<dt class="sig sig-object py" id="mmap.MAP_32BIT">679<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_32BIT</span></span><a class="headerlink" href="#mmap.MAP_32BIT" title="Link to this definition">¶</a></dt>680<dt class="sig sig-object py" id="mmap.MAP_ALIGNED_SUPER">681<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_ALIGNED_SUPER</span></span><a class="headerlink" href="#mmap.MAP_ALIGNED_SUPER" title="Link to this definition">¶</a></dt>682<dt class="sig sig-object py" id="mmap.MAP_ANON">683<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_ANON</span></span><a class="headerlink" href="#mmap.MAP_ANON" title="Link to this definition">¶</a></dt>684<dt class="sig sig-object py" id="mmap.MAP_ANONYMOUS">685<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_ANONYMOUS</span></span><a class="headerlink" href="#mmap.MAP_ANONYMOUS" title="Link to this definition">¶</a></dt>686<dt class="sig sig-object py" id="mmap.MAP_CONCEAL">687<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_CONCEAL</span></span><a class="headerlink" href="#mmap.MAP_CONCEAL" title="Link to this definition">¶</a></dt>688<dt class="sig sig-object py" id="mmap.MAP_DENYWRITE">689<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_DENYWRITE</span></span><a class="headerlink" href="#mmap.MAP_DENYWRITE" title="Link to this definition">¶</a></dt>690<dt class="sig sig-object py" id="mmap.MAP_EXECUTABLE">691<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_EXECUTABLE</span></span><a class="headerlink" href="#mmap.MAP_EXECUTABLE" title="Link to this definition">¶</a></dt>692<dt class="sig sig-object py" id="mmap.MAP_HASSEMAPHORE">693<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_HASSEMAPHORE</span></span><a class="headerlink" href="#mmap.MAP_HASSEMAPHORE" title="Link to this definition">¶</a></dt>694<dt class="sig sig-object py" id="mmap.MAP_JIT">695<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_JIT</span></span><a class="headerlink" href="#mmap.MAP_JIT" title="Link to this definition">¶</a></dt>696<dt class="sig sig-object py" id="mmap.MAP_NOCACHE">697<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_NOCACHE</span></span><a class="headerlink" href="#mmap.MAP_NOCACHE" title="Link to this definition">¶</a></dt>698<dt class="sig sig-object py" id="mmap.MAP_NOEXTEND">699<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_NOEXTEND</span></span><a class="headerlink" href="#mmap.MAP_NOEXTEND" title="Link to this definition">¶</a></dt>700<dt class="sig sig-object py" id="mmap.MAP_NORESERVE">701<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_NORESERVE</span></span><a class="headerlink" href="#mmap.MAP_NORESERVE" title="Link to this definition">¶</a></dt>702<dt class="sig sig-object py" id="mmap.MAP_POPULATE">703<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_POPULATE</span></span><a class="headerlink" href="#mmap.MAP_POPULATE" title="Link to this definition">¶</a></dt>704<dt class="sig sig-object py" id="mmap.MAP_RESILIENT_CODESIGN">705<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_RESILIENT_CODESIGN</span></span><a class="headerlink" href="#mmap.MAP_RESILIENT_CODESIGN" title="Link to this definition">¶</a></dt>706<dt class="sig sig-object py" id="mmap.MAP_RESILIENT_MEDIA">707<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_RESILIENT_MEDIA</span></span><a class="headerlink" href="#mmap.MAP_RESILIENT_MEDIA" title="Link to this definition">¶</a></dt>708<dt class="sig sig-object py" id="mmap.MAP_STACK">709<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_STACK</span></span><a class="headerlink" href="#mmap.MAP_STACK" title="Link to this definition">¶</a></dt>710<dt class="sig sig-object py" id="mmap.MAP_TPRO">711<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_TPRO</span></span><a class="headerlink" href="#mmap.MAP_TPRO" title="Link to this definition">¶</a></dt>712<dt class="sig sig-object py" id="mmap.MAP_TRANSLATED_ALLOW_EXECUTE">713<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_TRANSLATED_ALLOW_EXECUTE</span></span><a class="headerlink" href="#mmap.MAP_TRANSLATED_ALLOW_EXECUTE" title="Link to this definition">¶</a></dt>714<dt class="sig sig-object py" id="mmap.MAP_UNIX03">715<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MAP_UNIX03</span></span><a class="headerlink" href="#mmap.MAP_UNIX03" title="Link to this definition">¶</a></dt>716<dd><p>These are the various flags that can be passed to <a class="reference internal" href="#mmap.mmap" title="mmap.mmap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mmap.mmap()</span></code></a>.  <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_ALIGNED_SUPER</span></code>717is only available at FreeBSD and <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_CONCEAL</span></code> is only available at OpenBSD.  Note718that some options might not be present on some systems.</p>719<div class="versionchanged">720<p><span class="versionmodified changed">Changed in version 3.10: </span>Added <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_POPULATE</span></code> constant.</p>721</div>722<div class="versionadded">723<p><span class="versionmodified added">Added in version 3.11: </span>Added <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_STACK</span></code> constant.</p>724</div>725<div class="versionadded">726<p><span class="versionmodified added">Added in version 3.12: </span>Added <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_ALIGNED_SUPER</span></code> and <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_CONCEAL</span></code> constants.</p>727</div>728<div class="versionadded">729<p><span class="versionmodified added">Added in version 3.13: </span>Added <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_32BIT</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_HASSEMAPHORE</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_JIT</span></code>,730<code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_NOCACHE</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_NOEXTEND</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_NORESERVE</span></code>,731<code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_RESILIENT_CODESIGN</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_RESILIENT_MEDIA</span></code>,732<code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_TPRO</span></code>, <code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_TRANSLATED_ALLOW_EXECUTE</span></code>, and733<code class="xref py py-data docutils literal notranslate"><span class="pre">MAP_UNIX03</span></code> constants.</p>734</div>735</dd></dl>736 737</section>738<section id="ms-constants">739<span id="id2"></span><h2>MS_* Constants<a class="headerlink" href="#ms-constants" title="Link to this heading">¶</a></h2>740<dl class="py data">741<dt class="sig sig-object py" id="mmap.MS_SYNC">742<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MS_SYNC</span></span><a class="headerlink" href="#mmap.MS_SYNC" title="Link to this definition">¶</a></dt>743<dt class="sig sig-object py" id="mmap.MS_ASYNC">744<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MS_ASYNC</span></span><a class="headerlink" href="#mmap.MS_ASYNC" title="Link to this definition">¶</a></dt>745<dt class="sig sig-object py" id="mmap.MS_INVALIDATE">746<span class="sig-prename descclassname"><span class="pre">mmap.</span></span><span class="sig-name descname"><span class="pre">MS_INVALIDATE</span></span><a class="headerlink" href="#mmap.MS_INVALIDATE" title="Link to this definition">¶</a></dt>747<dd><p>These flags control the synchronization behavior for <a class="reference internal" href="#mmap.mmap.flush" title="mmap.mmap.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mmap.flush()</span></code></a>:</p>748<ul class="simple">749<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">MS_SYNC</span></code> - Synchronous flush: writes are scheduled and the call750blocks until they are physically written to storage.</p></li>751<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">MS_ASYNC</span></code> - Asynchronous flush: writes are scheduled but the call752returns immediately without waiting for completion.</p></li>753<li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">MS_INVALIDATE</span></code> - Invalidate cached data: invalidates other mappings754of the same file so they can see the changes.</p></li>755</ul>756<div class="versionadded">757<p><span class="versionmodified added">Added in version 3.15.</span></p>758</div>759</dd></dl>760 761</section>762</section>763 764 765            <div class="clearer"></div>766          </div>767        </div>768      </div>769      <div class="sphinxsidebar" role="navigation" aria-label="Main">770        <div class="sphinxsidebarwrapper">771  <div>772    <h3><a href="../contents.html">Table of Contents</a></h3>773    <ul>774<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code> — Memory-mapped file support</a><ul>775<li><a class="reference internal" href="#madv-constants">MADV_* Constants</a></li>776<li><a class="reference internal" href="#map-constants">MAP_* Constants</a></li>777<li><a class="reference internal" href="#ms-constants">MS_* Constants</a></li>778</ul>779</li>780</ul>781 782  </div>783  <div>784    <h4>Previous topic</h4>785    <p class="topless"><a href="signal.html"786                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code> — Set handlers for asynchronous events</a></p>787  </div>788  <div>789    <h4>Next topic</h4>790    <p class="topless"><a href="netdata.html"791                          title="next chapter">Internet Data Handling</a></p>792  </div>793  <script>794    document.addEventListener('DOMContentLoaded', () => {795        const title = document.querySelector('meta[property="og:title"]').content;796        const elements = document.querySelectorAll('.improvepage');797        const pageurl = window.location.href.split('?')[0];798        elements.forEach(element => {799            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));800            url.searchParams.set('pagetitle', title);801            url.searchParams.set('pageurl', pageurl);802            url.searchParams.set('pagesource', "library/mmap.rst");803            element.href = url.toString();804        });805    });806  </script>807  <div role="note" aria-label="source link">808    <h3>This page</h3>809    <ul class="this-page-menu">810      <li><a href="../bugs.html">Report a bug</a></li>811      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>812      <li>813        <a href="https://github.com/python/cpython/blob/main/Doc/library/mmap.rst?plain=1"814            rel="nofollow">Show source815        </a>816      </li>817      818    </ul>819  </div>820        </div>821<div id="sidebarbutton" title="Collapse sidebar">822<span>«</span>823</div>824 825      </div>826      <div class="clearer"></div>827    </div>  828    <div class="related" role="navigation" aria-label="Related">829      <h3>Navigation</h3>830      <ul>831        <li class="right" style="margin-right: 10px">832          <a href="../genindex.html" title="General Index"833             >index</a></li>834        <li class="right" >835          <a href="../py-modindex.html" title="Python Module Index"836             >modules</a> |</li>837        <li class="right" >838          <a href="netdata.html" title="Internet Data Handling"839             >next</a> |</li>840        <li class="right" >841          <a href="signal.html" title="signal — Set handlers for asynchronous events"842             >previous</a> |</li>843 844          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>845          <li><a href="https://www.python.org/">Python</a> &#187;</li>846          <li class="switchers">847            <div class="language_switcher_placeholder"></div>848            <div class="version_switcher_placeholder"></div>849          </li>850          <li>851              852          </li>853    <li id="cpython-language-and-version">854      <a href="../index.html">3.15.0a6 Documentation</a> &#187;855    </li>856 857          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>858          <li class="nav-item nav-item-2"><a href="ipc.html" >Networking and Interprocess Communication</a> &#187;</li>859        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code> — Memory-mapped file support</a></li>860                <li class="right">861                    862 863    <div class="inline-search" role="search">864        <form class="inline-search" action="../search.html" method="get">865          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">866          <input type="submit" value="Go">867        </form>868    </div>869                     |870                </li>871            <li class="right">872<label class="theme-selector-label">873    Theme874    <select class="theme-selector" oninput="activateTheme(this.value)">875        <option value="auto" selected>Auto</option>876        <option value="light">Light</option>877        <option value="dark">Dark</option>878    </select>879</label> |</li>880            881      </ul>882    </div>  883    <div class="footer">884    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.885    <br>886    This page is licensed under the Python Software Foundation License Version 2.887    <br>888    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.889    <br>890    891      See <a href="/license.html">History and License</a> for more information.<br>892    893    894    <br>895 896    The Python Software Foundation is a non-profit corporation.897<a href="https://www.python.org/psf/donations/">Please donate.</a>898<br>899    <br>900      Last updated on Mar 10, 2026 (08:58 UTC).901    902      <a href="/bugs.html">Found a bug</a>?903    904    <br>905 906    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.907    </div>908 909  </body>910</html>