Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
concurrent.interpreters.html770 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="concurrent.interpreters — Multiple interpreters in the same process" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/concurrent.interpreters.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/concurrent/interpreters The concurrent.interpreters module constructs higher-level interfaces on top of the lower level_interpreters module. The module is primarily meant to provid..." />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_concurrent.interpreters_f6b8e551.png" />15<meta property="og:image:alt" content="Source code: Lib/concurrent/interpreters The concurrent.interpreters module constructs higher-level interfaces on top of the lower level_interpreters module. The module is primarily meant to provid..." />16<meta name="description" content="Source code: Lib/concurrent/interpreters The concurrent.interpreters module constructs higher-level interfaces on top of the lower level_interpreters module. The module is primarily meant to provid..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>concurrent.interpreters — Multiple interpreters in the same process &#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="subprocess — Subprocess management" href="subprocess.html" />43    <link rel="prev" title="concurrent.futures — Launching parallel tasks" href="concurrent.futures.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/concurrent.interpreters.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">concurrent.interpreters</span></code> — Multiple interpreters in the same process</a><ul>108<li><a class="reference internal" href="#key-details">Key details</a></li>109<li><a class="reference internal" href="#introduction">Introduction</a><ul>110<li><a class="reference internal" href="#multiple-interpreters-and-isolation">Multiple Interpreters and Isolation</a></li>111<li><a class="reference internal" href="#running-in-an-interpreter">Running in an Interpreter</a></li>112<li><a class="reference internal" href="#concurrency-and-parallelism">Concurrency and Parallelism</a></li>113<li><a class="reference internal" href="#communication-between-interpreters">Communication Between Interpreters</a></li>114<li><a class="reference internal" href="#sharing-objects">“Sharing” Objects</a></li>115</ul>116</li>117<li><a class="reference internal" href="#reference">Reference</a><ul>118<li><a class="reference internal" href="#interpreter-objects">Interpreter objects</a></li>119<li><a class="reference internal" href="#exceptions">Exceptions</a></li>120<li><a class="reference internal" href="#communicating-between-interpreters">Communicating Between Interpreters</a></li>121</ul>122</li>123<li><a class="reference internal" href="#basic-usage">Basic usage</a></li>124</ul>125</li>126</ul>127 128  </div>129  <div>130    <h4>Previous topic</h4>131    <p class="topless"><a href="concurrent.futures.html"132                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code> — Launching parallel tasks</a></p>133  </div>134  <div>135    <h4>Next topic</h4>136    <p class="topless"><a href="subprocess.html"137                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code> — Subprocess management</a></p>138  </div>139  <script>140    document.addEventListener('DOMContentLoaded', () => {141        const title = document.querySelector('meta[property="og:title"]').content;142        const elements = document.querySelectorAll('.improvepage');143        const pageurl = window.location.href.split('?')[0];144        elements.forEach(element => {145            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));146            url.searchParams.set('pagetitle', title);147            url.searchParams.set('pageurl', pageurl);148            url.searchParams.set('pagesource', "library/concurrent.interpreters.rst");149            element.href = url.toString();150        });151    });152  </script>153  <div role="note" aria-label="source link">154    <h3>This page</h3>155    <ul class="this-page-menu">156      <li><a href="../bugs.html">Report a bug</a></li>157      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>158      <li>159        <a href="https://github.com/python/cpython/blob/main/Doc/library/concurrent.interpreters.rst?plain=1"160            rel="nofollow">Show source161        </a>162      </li>163      164    </ul>165  </div>166        </nav>167    </div>168</div>169 170  171    <div class="related" role="navigation" aria-label="Related">172      <h3>Navigation</h3>173      <ul>174        <li class="right" style="margin-right: 10px">175          <a href="../genindex.html" title="General Index"176             accesskey="I">index</a></li>177        <li class="right" >178          <a href="../py-modindex.html" title="Python Module Index"179             >modules</a> |</li>180        <li class="right" >181          <a href="subprocess.html" title="subprocess — Subprocess management"182             accesskey="N">next</a> |</li>183        <li class="right" >184          <a href="concurrent.futures.html" title="concurrent.futures — Launching parallel tasks"185             accesskey="P">previous</a> |</li>186 187          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>188          <li><a href="https://www.python.org/">Python</a> &#187;</li>189          <li class="switchers">190            <div class="language_switcher_placeholder"></div>191            <div class="version_switcher_placeholder"></div>192          </li>193          <li>194              195          </li>196    <li id="cpython-language-and-version">197      <a href="../index.html">3.15.0a6 Documentation</a> &#187;198    </li>199 200          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>201          <li class="nav-item nav-item-2"><a href="concurrency.html" accesskey="U">Concurrent Execution</a> &#187;</li>202        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> — Multiple interpreters in the same process</a></li>203                <li class="right">204                    205 206    <div class="inline-search" role="search">207        <form class="inline-search" action="../search.html" method="get">208          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">209          <input type="submit" value="Go">210        </form>211    </div>212                     |213                </li>214            <li class="right">215<label class="theme-selector-label">216    Theme217    <select class="theme-selector" oninput="activateTheme(this.value)">218        <option value="auto" selected>Auto</option>219        <option value="light">Light</option>220        <option value="dark">Dark</option>221    </select>222</label> |</li>223            224      </ul>225    </div>    226 227    <div class="document">228      <div class="documentwrapper">229        <div class="bodywrapper">230          <div class="body" role="main">231            232  <section id="module-concurrent.interpreters">233<span id="concurrent-interpreters-multiple-interpreters-in-the-same-process"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> — Multiple interpreters in the same process<a class="headerlink" href="#module-concurrent.interpreters" title="Link to this heading">¶</a></h1>234<div class="versionadded">235<p><span class="versionmodified added">Added in version 3.14.</span></p>236</div>237<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/concurrent/interpreters">Lib/concurrent/interpreters</a></p>238<hr class="docutils" />239<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> module constructs higher-level240interfaces on top of the lower level <code class="xref py py-mod docutils literal notranslate"><span class="pre">_interpreters</span></code> module.</p>241<p>The module is primarily meant to provide a basic API for managing242interpreters (AKA “subinterpreters”) and running things in them.243Running mostly involves switching to an interpreter (in the current244thread) and calling a function in that execution context.</p>245<p>For concurrency, interpreters themselves (and this module) don’t246provide much more than isolation, which on its own isn’t useful.247Actual concurrency is available separately through248<a class="reference internal" href="threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threads</span></code></a>  See <a class="reference internal" href="#interp-concurrency">below</a></p>249<div class="admonition seealso">250<p class="admonition-title">See also</p>251<dl class="simple">252<dt><a class="reference internal" href="concurrent.futures.html#concurrent.futures.InterpreterPoolExecutor" title="concurrent.futures.InterpreterPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">InterpreterPoolExecutor</span></code></a></dt><dd><p>Combines threads with interpreters in a familiar interface.</p>253</dd>254</dl>255<dl class="simple">256<dt><a class="reference internal" href="../howto/isolating-extensions.html#isolating-extensions-howto"><span class="std std-ref">Isolating Extension Modules</span></a></dt><dd><p>How to update an extension module to support multiple interpreters.</p>257</dd>258</dl>259<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0554/"><strong>PEP 554</strong></a></p>260<p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0734/"><strong>PEP 734</strong></a></p>261<p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0684/"><strong>PEP 684</strong></a></p>262</div>263<div class="availability docutils container">264<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>265<p>This module does not work or is not available on WebAssembly. See266<a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>267</div>268<section id="key-details">269<h2>Key details<a class="headerlink" href="#key-details" title="Link to this heading">¶</a></h2>270<p>Before we dive in further, there are a small number of details271to keep in mind about using multiple interpreters:</p>272<ul class="simple">273<li><p><a class="reference internal" href="#interp-isolation">isolated</a>, by default</p></li>274<li><p>no implicit threads</p></li>275<li><p>not all PyPI packages support use in multiple interpreters yet</p></li>276</ul>277</section>278<section id="introduction">279<span id="interpreters-intro"></span><h2>Introduction<a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h2>280<p>An “interpreter” is effectively the execution context of the Python281runtime.  It contains all of the state the runtime needs to execute282a program.  This includes things like the import state and builtins.283(Each thread, even if there’s only the main thread, has some extra284runtime state, in addition to the current interpreter, related to285the current exception and the bytecode eval loop.)</p>286<p>The concept and functionality of the interpreter have been a part of287Python since version 2.2, but the feature was only available through288the C-API and not well known, and the <a class="reference internal" href="#interp-isolation">isolation</a>289was relatively incomplete until version 3.12.</p>290<section id="multiple-interpreters-and-isolation">291<span id="interp-isolation"></span><h3>Multiple Interpreters and Isolation<a class="headerlink" href="#multiple-interpreters-and-isolation" title="Link to this heading">¶</a></h3>292<p>A Python implementation may support using multiple interpreters in the293same process.  CPython has this support.  Each interpreter is294effectively isolated from the others (with a limited number of295carefully managed process-global exceptions to the rule).</p>296<p>That isolation is primarily useful as a strong separation between297distinct logical components of a program, where you want to have298careful control of how those components interact.</p>299<div class="admonition note">300<p class="admonition-title">Note</p>301<p>Interpreters in the same process can technically never be strictly302isolated from one another since there are few restrictions on memory303access within the same process.  The Python runtime makes a best304effort at isolation but extension modules may easily violate that.305Therefore, do not use multiple interpreters in security-sensitive306situations, where they shouldn’t have access to each other’s data.</p>307</div>308</section>309<section id="running-in-an-interpreter">310<h3>Running in an Interpreter<a class="headerlink" href="#running-in-an-interpreter" title="Link to this heading">¶</a></h3>311<p>Running in a different interpreter involves switching to it in the312current thread and then calling some function.  The runtime will313execute the function using the current interpreter’s state.  The314<code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> module provides a basic API for315creating and managing interpreters, as well as the switch-and-call316operation.</p>317<p>No other threads are automatically started for the operation.318There is <a class="reference internal" href="#interp-call-in-thread">a helper</a> for that though.319There is another dedicated helper for calling the builtin320<a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> in an interpreter.</p>321<p>When <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> (or <a class="reference internal" href="functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a>) are called in an interpreter,322they run using the interpreter’s <code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code> module as the323“globals” namespace.  The same is true for functions that aren’t324associated with any module.  This is the same as how scripts invoked325from the command-line run in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code> module.</p>326</section>327<section id="concurrency-and-parallelism">328<span id="interp-concurrency"></span><h3>Concurrency and Parallelism<a class="headerlink" href="#concurrency-and-parallelism" title="Link to this heading">¶</a></h3>329<p>As noted earlier, interpreters do not provide any concurrency330on their own.  They strictly represent the isolated execution331context the runtime will use <em>in the current thread</em>.  That isolation332makes them similar to processes, but they still enjoy in-process333efficiency, like threads.</p>334<p>All that said, interpreters do naturally support certain flavors of335concurrency.336There’s a powerful side effect of that isolation.  It enables a337different approach to concurrency than you can take with async or338threads.  It’s a similar concurrency model to CSP or the actor model,339a model which is relatively easy to reason about.</p>340<p>You can take advantage of that concurrency model in a single thread,341switching back and forth between interpreters, Stackless-style.342However, this model is more useful when you combine interpreters343with multiple threads.  This mostly involves starting a new thread,344where you switch to another interpreter and run what you want there.</p>345<p>Each actual thread in Python, even if you’re only running in the main346thread, has its own <em>current</em> execution context.  Multiple threads can347use the same interpreter or different ones.</p>348<p>At a high level, you can think of the combination of threads and349interpreters as threads with opt-in sharing.</p>350<p>As a significant bonus, interpreters are sufficiently isolated that351they do not share the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a>, which means combining threads with352multiple interpreters enables full multi-core parallelism.353(This has been the case since Python 3.12.)</p>354</section>355<section id="communication-between-interpreters">356<h3>Communication Between Interpreters<a class="headerlink" href="#communication-between-interpreters" title="Link to this heading">¶</a></h3>357<p>In practice, multiple interpreters are useful only if we have a way358to communicate between them.  This usually involves some form of359message passing, but can even mean sharing data in some carefully360managed way.</p>361<p>With this in mind, the <code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> module provides362a <a class="reference internal" href="queue.html#queue.Queue" title="queue.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">queue.Queue</span></code></a> implementation, available through363<a class="reference internal" href="#concurrent.interpreters.create_queue" title="concurrent.interpreters.create_queue"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_queue()</span></code></a>.</p>364</section>365<section id="sharing-objects">366<span id="interp-object-sharing"></span><h3>“Sharing” Objects<a class="headerlink" href="#sharing-objects" title="Link to this heading">¶</a></h3>367<p>Any data actually shared between interpreters loses the thread-safety368provided by the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a>.  There are various options for dealing with369this in extension modules.  However, from Python code the lack of370thread-safety means objects can’t actually be shared, with a few371exceptions.  Instead, a copy must be created, which means mutable372objects won’t stay in sync.</p>373<p>By default, most objects are copied with <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> when they are374passed to another interpreter.  Nearly all of the immutable builtin375objects are either directly shared or copied efficiently.  For example:</p>376<ul class="simple">377<li><p><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></li>378<li><p><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> (<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> and <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>)</p></li>379<li><p><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></p></li>380<li><p><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></li>381<li><p><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></p></li>382<li><p><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></p></li>383<li><p><a class="reference internal" href="stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> (of similarly supported objects)</p></li>384</ul>385<p>There is a small number of Python types that actually share mutable386data between interpreters:</p>387<ul class="simple">388<li><p><a class="reference internal" href="stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a></p></li>389<li><p><a class="reference internal" href="#concurrent.interpreters.Queue" title="concurrent.interpreters.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">Queue</span></code></a></p></li>390</ul>391</section>392</section>393<section id="reference">394<h2>Reference<a class="headerlink" href="#reference" title="Link to this heading">¶</a></h2>395<p>This module defines the following functions:</p>396<dl class="py function">397<dt class="sig sig-object py" id="concurrent.interpreters.list_all">398<span class="sig-prename descclassname"><span class="pre">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">list_all</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.list_all" title="Link to this definition">¶</a></dt>399<dd><p>Return a <a class="reference internal" href="stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> of <a class="reference internal" href="#concurrent.interpreters.Interpreter" title="concurrent.interpreters.Interpreter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Interpreter</span></code></a> objects,400one for each existing interpreter.</p>401</dd></dl>402 403<dl class="py function">404<dt class="sig sig-object py" id="concurrent.interpreters.get_current">405<span class="sig-prename descclassname"><span class="pre">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">get_current</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.get_current" title="Link to this definition">¶</a></dt>406<dd><p>Return an <a class="reference internal" href="#concurrent.interpreters.Interpreter" title="concurrent.interpreters.Interpreter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Interpreter</span></code></a> object for the currently running407interpreter.</p>408</dd></dl>409 410<dl class="py function">411<dt class="sig sig-object py" id="concurrent.interpreters.get_main">412<span class="sig-prename descclassname"><span class="pre">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">get_main</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.get_main" title="Link to this definition">¶</a></dt>413<dd><p>Return an <a class="reference internal" href="#concurrent.interpreters.Interpreter" title="concurrent.interpreters.Interpreter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Interpreter</span></code></a> object for the main interpreter.414This is the interpreter the runtime created to run the <a class="reference internal" href="../glossary.html#term-REPL"><span class="xref std std-term">REPL</span></a>415or the script given at the command-line.  It is usually the only one.</p>416</dd></dl>417 418<dl class="py function">419<dt class="sig sig-object py" id="concurrent.interpreters.create">420<span class="sig-prename descclassname"><span class="pre">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">create</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.create" title="Link to this definition">¶</a></dt>421<dd><p>Initialize a new (idle) Python interpreter422and return a <a class="reference internal" href="#concurrent.interpreters.Interpreter" title="concurrent.interpreters.Interpreter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Interpreter</span></code></a> object for it.</p>423</dd></dl>424 425<dl class="py function">426<dt class="sig sig-object py" id="concurrent.interpreters.create_queue">427<span class="sig-prename descclassname"><span class="pre">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">create_queue</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.create_queue" title="Link to this definition">¶</a></dt>428<dd><p>Initialize a new cross-interpreter queue and return a <a class="reference internal" href="#concurrent.interpreters.Queue" title="concurrent.interpreters.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">Queue</span></code></a>429object for it.</p>430</dd></dl>431 432<section id="interpreter-objects">433<h3>Interpreter objects<a class="headerlink" href="#interpreter-objects" title="Link to this heading">¶</a></h3>434<dl class="py class">435<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter">436<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">Interpreter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.Interpreter" title="Link to this definition">¶</a></dt>437<dd><p>A single interpreter in the current process.</p>438<p>Generally, <code class="xref py py-class docutils literal notranslate"><span class="pre">Interpreter</span></code> shouldn’t be called directly.439Instead, use <a class="reference internal" href="#concurrent.interpreters.create" title="concurrent.interpreters.create"><code class="xref py py-func docutils literal notranslate"><span class="pre">create()</span></code></a> or one of the other module functions.</p>440<dl class="py attribute">441<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.id">442<span class="sig-name descname"><span class="pre">id</span></span><a class="headerlink" href="#concurrent.interpreters.Interpreter.id" title="Link to this definition">¶</a></dt>443<dd><p>(read-only)</p>444<p>The underlying interpreter’s ID.</p>445</dd></dl>446 447<dl class="py attribute">448<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.whence">449<span class="sig-name descname"><span class="pre">whence</span></span><a class="headerlink" href="#concurrent.interpreters.Interpreter.whence" title="Link to this definition">¶</a></dt>450<dd><p>(read-only)</p>451<p>A string describing where the interpreter came from.</p>452</dd></dl>453 454<dl class="py method">455<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.is_running">456<span class="sig-name descname"><span class="pre">is_running</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.Interpreter.is_running" title="Link to this definition">¶</a></dt>457<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the interpreter is currently executing code458in its <code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code> module and <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>459</dd></dl>460 461<dl class="py method">462<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.close">463<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="#concurrent.interpreters.Interpreter.close" title="Link to this definition">¶</a></dt>464<dd><p>Finalize and destroy the interpreter.</p>465</dd></dl>466 467<dl class="py method">468<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.prepare_main">469<span class="sig-name descname"><span class="pre">prepare_main</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ns</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="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="#concurrent.interpreters.Interpreter.prepare_main" title="Link to this definition">¶</a></dt>470<dd><p>Bind objects in the interpreter’s <code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code> module.</p>471<p>Some objects are actually shared and some are copied efficiently,472but most are copied via <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a>.  See <a class="reference internal" href="#interp-object-sharing"><span class="std std-ref">“Sharing” Objects</span></a>.</p>473</dd></dl>474 475<dl class="py method">476<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.exec">477<span class="sig-name descname"><span class="pre">exec</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>, <em class="sig-param"><span class="n"><span class="pre">dedent</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="#concurrent.interpreters.Interpreter.exec" title="Link to this definition">¶</a></dt>478<dd><p>Run the given source code in the interpreter (in the current thread).</p>479</dd></dl>480 481<dl class="py method">482<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.call">483<span class="sig-name descname"><span class="pre">call</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">callable</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="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="#concurrent.interpreters.Interpreter.call" title="Link to this definition">¶</a></dt>484<dd><p>Return the result of calling running the given function in the485interpreter (in the current thread).</p>486</dd></dl>487 488<dl class="py method" id="interp-call-in-thread">489<dt class="sig sig-object py" id="concurrent.interpreters.Interpreter.call_in_thread">490<span class="sig-name descname"><span class="pre">call_in_thread</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">callable</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="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="#concurrent.interpreters.Interpreter.call_in_thread" title="Link to this definition">¶</a></dt>491<dd><p>Run the given function in the interpreter (in a new thread).</p>492</dd></dl>493 494</dd></dl>495 496</section>497<section id="exceptions">498<h3>Exceptions<a class="headerlink" href="#exceptions" title="Link to this heading">¶</a></h3>499<dl class="py exception">500<dt class="sig sig-object py" id="concurrent.interpreters.InterpreterError">501<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">InterpreterError</span></span><a class="headerlink" href="#concurrent.interpreters.InterpreterError" title="Link to this definition">¶</a></dt>502<dd><p>This exception, a subclass of <a class="reference internal" href="exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>, is raised when503an interpreter-related error happens.</p>504</dd></dl>505 506<dl class="py exception">507<dt class="sig sig-object py" id="concurrent.interpreters.InterpreterNotFoundError">508<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">InterpreterNotFoundError</span></span><a class="headerlink" href="#concurrent.interpreters.InterpreterNotFoundError" title="Link to this definition">¶</a></dt>509<dd><p>This exception, a subclass of <a class="reference internal" href="#concurrent.interpreters.InterpreterError" title="concurrent.interpreters.InterpreterError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterpreterError</span></code></a>, is raised when510the targeted interpreter no longer exists.</p>511</dd></dl>512 513<dl class="py exception">514<dt class="sig sig-object py" id="concurrent.interpreters.ExecutionFailed">515<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">ExecutionFailed</span></span><a class="headerlink" href="#concurrent.interpreters.ExecutionFailed" title="Link to this definition">¶</a></dt>516<dd><p>This exception, a subclass of <a class="reference internal" href="#concurrent.interpreters.InterpreterError" title="concurrent.interpreters.InterpreterError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterpreterError</span></code></a>, is raised when517the running code raised an uncaught exception.</p>518<dl class="py attribute">519<dt class="sig sig-object py" id="concurrent.interpreters.ExecutionFailed.excinfo">520<span class="sig-name descname"><span class="pre">excinfo</span></span><a class="headerlink" href="#concurrent.interpreters.ExecutionFailed.excinfo" title="Link to this definition">¶</a></dt>521<dd><p>A basic snapshot of the exception raised in the other interpreter.</p>522</dd></dl>523 524</dd></dl>525 526<dl class="py exception">527<dt class="sig sig-object py" id="concurrent.interpreters.NotShareableError">528<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">NotShareableError</span></span><a class="headerlink" href="#concurrent.interpreters.NotShareableError" title="Link to this definition">¶</a></dt>529<dd><p>This exception, a subclass of <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 when530an object cannot be sent to another interpreter.</p>531</dd></dl>532 533</section>534<section id="communicating-between-interpreters">535<h3>Communicating Between Interpreters<a class="headerlink" href="#communicating-between-interpreters" title="Link to this heading">¶</a></h3>536<dl class="py class">537<dt class="sig sig-object py" id="concurrent.interpreters.Queue">538<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">Queue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#concurrent.interpreters.Queue" title="Link to this definition">¶</a></dt>539<dd><p>A wrapper around a low-level, cross-interpreter queue, which540implements the <a class="reference internal" href="queue.html#queue.Queue" title="queue.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">queue.Queue</span></code></a> interface.  The underlying queue541can only be created through <a class="reference internal" href="#concurrent.interpreters.create_queue" title="concurrent.interpreters.create_queue"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_queue()</span></code></a>.</p>542<p>Some objects are actually shared and some are copied efficiently,543but most are copied via <a class="reference internal" href="pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a>.  See <a class="reference internal" href="#interp-object-sharing"><span class="std std-ref">“Sharing” Objects</span></a>.</p>544<dl class="py attribute">545<dt class="sig sig-object py" id="concurrent.interpreters.Queue.id">546<span class="sig-name descname"><span class="pre">id</span></span><a class="headerlink" href="#concurrent.interpreters.Queue.id" title="Link to this definition">¶</a></dt>547<dd><p>(read-only)</p>548<p>The queue’s ID.</p>549</dd></dl>550 551</dd></dl>552 553<dl class="py exception">554<dt class="sig sig-object py" id="concurrent.interpreters.QueueEmptyError">555<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">QueueEmptyError</span></span><a class="headerlink" href="#concurrent.interpreters.QueueEmptyError" title="Link to this definition">¶</a></dt>556<dd><p>This exception, a subclass of <a class="reference internal" href="queue.html#queue.Empty" title="queue.Empty"><code class="xref py py-exc docutils literal notranslate"><span class="pre">queue.Empty</span></code></a>, is raised from557<code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.get()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.get_nowait()</span></code> when the queue558is empty.</p>559</dd></dl>560 561<dl class="py exception">562<dt class="sig sig-object py" id="concurrent.interpreters.QueueFullError">563<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">concurrent.interpreters.</span></span><span class="sig-name descname"><span class="pre">QueueFullError</span></span><a class="headerlink" href="#concurrent.interpreters.QueueFullError" title="Link to this definition">¶</a></dt>564<dd><p>This exception, a subclass of <a class="reference internal" href="queue.html#queue.Full" title="queue.Full"><code class="xref py py-exc docutils literal notranslate"><span class="pre">queue.Full</span></code></a>, is raised from565<code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.put()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.put_nowait()</span></code> when the queue566is full.</p>567</dd></dl>568 569</section>570</section>571<section id="basic-usage">572<h2>Basic usage<a class="headerlink" href="#basic-usage" title="Link to this heading">¶</a></h2>573<p>Creating an interpreter and running code in it:</p>574<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">concurrent</span><span class="w"> </span><span class="kn">import</span> <span class="n">interpreters</span>575 576<span class="n">interp</span> <span class="o">=</span> <span class="n">interpreters</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>577 578<span class="c1"># Run in the current OS thread.</span>579 580<span class="n">interp</span><span class="o">.</span><span class="n">exec</span><span class="p">(</span><span class="s1">&#39;print(&quot;spam!&quot;)&#39;</span><span class="p">)</span>581 582<span class="n">interp</span><span class="o">.</span><span class="n">exec</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;if True:</span>583<span class="s2">    print(&#39;spam!&#39;)</span>584<span class="s2">    &quot;&quot;&quot;</span><span class="p">)</span>585 586<span class="kn">from</span><span class="w"> </span><span class="nn">textwrap</span><span class="w"> </span><span class="kn">import</span> <span class="n">dedent</span>587<span class="n">interp</span><span class="o">.</span><span class="n">exec</span><span class="p">(</span><span class="n">dedent</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>588<span class="s2">    print(&#39;spam!&#39;)</span>589<span class="s2">    &quot;&quot;&quot;</span><span class="p">))</span>590 591<span class="k">def</span><span class="w"> </span><span class="nf">run</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>592    <span class="k">return</span> <span class="n">arg</span>593 594<span class="n">res</span> <span class="o">=</span> <span class="n">interp</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="n">run</span><span class="p">,</span> <span class="s1">&#39;spam!&#39;</span><span class="p">)</span>595<span class="nb">print</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>596 597<span class="k">def</span><span class="w"> </span><span class="nf">run</span><span class="p">():</span>598    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;spam!&#39;</span><span class="p">)</span>599 600<span class="n">interp</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="n">run</span><span class="p">)</span>601 602<span class="c1"># Run in new OS thread.</span>603 604<span class="n">t</span> <span class="o">=</span> <span class="n">interp</span><span class="o">.</span><span class="n">call_in_thread</span><span class="p">(</span><span class="n">run</span><span class="p">)</span>605<span class="n">t</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>606</pre></div>607</div>608</section>609</section>610 611 612            <div class="clearer"></div>613          </div>614        </div>615      </div>616      <div class="sphinxsidebar" role="navigation" aria-label="Main">617        <div class="sphinxsidebarwrapper">618  <div>619    <h3><a href="../contents.html">Table of Contents</a></h3>620    <ul>621<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> — Multiple interpreters in the same process</a><ul>622<li><a class="reference internal" href="#key-details">Key details</a></li>623<li><a class="reference internal" href="#introduction">Introduction</a><ul>624<li><a class="reference internal" href="#multiple-interpreters-and-isolation">Multiple Interpreters and Isolation</a></li>625<li><a class="reference internal" href="#running-in-an-interpreter">Running in an Interpreter</a></li>626<li><a class="reference internal" href="#concurrency-and-parallelism">Concurrency and Parallelism</a></li>627<li><a class="reference internal" href="#communication-between-interpreters">Communication Between Interpreters</a></li>628<li><a class="reference internal" href="#sharing-objects">“Sharing” Objects</a></li>629</ul>630</li>631<li><a class="reference internal" href="#reference">Reference</a><ul>632<li><a class="reference internal" href="#interpreter-objects">Interpreter objects</a></li>633<li><a class="reference internal" href="#exceptions">Exceptions</a></li>634<li><a class="reference internal" href="#communicating-between-interpreters">Communicating Between Interpreters</a></li>635</ul>636</li>637<li><a class="reference internal" href="#basic-usage">Basic usage</a></li>638</ul>639</li>640</ul>641 642  </div>643  <div>644    <h4>Previous topic</h4>645    <p class="topless"><a href="concurrent.futures.html"646                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code> — Launching parallel tasks</a></p>647  </div>648  <div>649    <h4>Next topic</h4>650    <p class="topless"><a href="subprocess.html"651                          title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code> — Subprocess management</a></p>652  </div>653  <script>654    document.addEventListener('DOMContentLoaded', () => {655        const title = document.querySelector('meta[property="og:title"]').content;656        const elements = document.querySelectorAll('.improvepage');657        const pageurl = window.location.href.split('?')[0];658        elements.forEach(element => {659            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));660            url.searchParams.set('pagetitle', title);661            url.searchParams.set('pageurl', pageurl);662            url.searchParams.set('pagesource', "library/concurrent.interpreters.rst");663            element.href = url.toString();664        });665    });666  </script>667  <div role="note" aria-label="source link">668    <h3>This page</h3>669    <ul class="this-page-menu">670      <li><a href="../bugs.html">Report a bug</a></li>671      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>672      <li>673        <a href="https://github.com/python/cpython/blob/main/Doc/library/concurrent.interpreters.rst?plain=1"674            rel="nofollow">Show source675        </a>676      </li>677      678    </ul>679  </div>680        </div>681<div id="sidebarbutton" title="Collapse sidebar">682<span>«</span>683</div>684 685      </div>686      <div class="clearer"></div>687    </div>  688    <div class="related" role="navigation" aria-label="Related">689      <h3>Navigation</h3>690      <ul>691        <li class="right" style="margin-right: 10px">692          <a href="../genindex.html" title="General Index"693             >index</a></li>694        <li class="right" >695          <a href="../py-modindex.html" title="Python Module Index"696             >modules</a> |</li>697        <li class="right" >698          <a href="subprocess.html" title="subprocess — Subprocess management"699             >next</a> |</li>700        <li class="right" >701          <a href="concurrent.futures.html" title="concurrent.futures — Launching parallel tasks"702             >previous</a> |</li>703 704          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>705          <li><a href="https://www.python.org/">Python</a> &#187;</li>706          <li class="switchers">707            <div class="language_switcher_placeholder"></div>708            <div class="version_switcher_placeholder"></div>709          </li>710          <li>711              712          </li>713    <li id="cpython-language-and-version">714      <a href="../index.html">3.15.0a6 Documentation</a> &#187;715    </li>716 717          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>718          <li class="nav-item nav-item-2"><a href="concurrency.html" >Concurrent Execution</a> &#187;</li>719        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.interpreters</span></code> — Multiple interpreters in the same process</a></li>720                <li class="right">721                    722 723    <div class="inline-search" role="search">724        <form class="inline-search" action="../search.html" method="get">725          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">726          <input type="submit" value="Go">727        </form>728    </div>729                     |730                </li>731            <li class="right">732<label class="theme-selector-label">733    Theme734    <select class="theme-selector" oninput="activateTheme(this.value)">735        <option value="auto" selected>Auto</option>736        <option value="light">Light</option>737        <option value="dark">Dark</option>738    </select>739</label> |</li>740            741      </ul>742    </div>  743    <div class="footer">744    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.745    <br>746    This page is licensed under the Python Software Foundation License Version 2.747    <br>748    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.749    <br>750    751      See <a href="/license.html">History and License</a> for more information.<br>752    753    754    <br>755 756    The Python Software Foundation is a non-profit corporation.757<a href="https://www.python.org/psf/donations/">Please donate.</a>758<br>759    <br>760      Last updated on Mar 10, 2026 (08:58 UTC).761    762      <a href="/bugs.html">Found a bug</a>?763    764    <br>765 766    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.767    </div>768 769  </body>770</html>