Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
asyncio-graph.html494 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="Call Graph Introspection" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/asyncio-graph.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/asyncio/graph.py asyncio has powerful runtime call graph introspection utilities to trace the entire call graph of a running coroutine or task, or a suspended future. These utiliti..." />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_asyncio-graph_240d61f9.png" />15<meta property="og:image:alt" content="Source code: Lib/asyncio/graph.py asyncio has powerful runtime call graph introspection utilities to trace the entire call graph of a running coroutine or task, or a suspended future. These utiliti..." />16<meta name="description" content="Source code: Lib/asyncio/graph.py asyncio has powerful runtime call graph introspection utilities to trace the entire call graph of a running coroutine or task, or a suspended future. These utiliti..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>Call Graph Introspection &#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="Event Loop" href="asyncio-eventloop.html" />43    <link rel="prev" title="Exceptions" href="asyncio-exceptions.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/asyncio-graph.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="#">Call Graph Introspection</a><ul>108<li><a class="reference internal" href="#low-level-utility-functions">Low level utility functions</a></li>109</ul>110</li>111</ul>112 113  </div>114  <div>115    <h4>Previous topic</h4>116    <p class="topless"><a href="asyncio-exceptions.html"117                          title="previous chapter">Exceptions</a></p>118  </div>119  <div>120    <h4>Next topic</h4>121    <p class="topless"><a href="asyncio-eventloop.html"122                          title="next chapter">Event Loop</a></p>123  </div>124  <script>125    document.addEventListener('DOMContentLoaded', () => {126        const title = document.querySelector('meta[property="og:title"]').content;127        const elements = document.querySelectorAll('.improvepage');128        const pageurl = window.location.href.split('?')[0];129        elements.forEach(element => {130            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131            url.searchParams.set('pagetitle', title);132            url.searchParams.set('pageurl', pageurl);133            url.searchParams.set('pagesource', "library/asyncio-graph.rst");134            element.href = url.toString();135        });136    });137  </script>138  <div role="note" aria-label="source link">139    <h3>This page</h3>140    <ul class="this-page-menu">141      <li><a href="../bugs.html">Report a bug</a></li>142      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143      <li>144        <a href="https://github.com/python/cpython/blob/main/Doc/library/asyncio-graph.rst?plain=1"145            rel="nofollow">Show source146        </a>147      </li>148      149    </ul>150  </div>151        </nav>152    </div>153</div>154 155  156    <div class="related" role="navigation" aria-label="Related">157      <h3>Navigation</h3>158      <ul>159        <li class="right" style="margin-right: 10px">160          <a href="../genindex.html" title="General Index"161             accesskey="I">index</a></li>162        <li class="right" >163          <a href="../py-modindex.html" title="Python Module Index"164             >modules</a> |</li>165        <li class="right" >166          <a href="asyncio-eventloop.html" title="Event Loop"167             accesskey="N">next</a> |</li>168        <li class="right" >169          <a href="asyncio-exceptions.html" title="Exceptions"170             accesskey="P">previous</a> |</li>171 172          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173          <li><a href="https://www.python.org/">Python</a> &#187;</li>174          <li class="switchers">175            <div class="language_switcher_placeholder"></div>176            <div class="version_switcher_placeholder"></div>177          </li>178          <li>179              180          </li>181    <li id="cpython-language-and-version">182      <a href="../index.html">3.15.0a6 Documentation</a> &#187;183    </li>184 185          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>186          <li class="nav-item nav-item-2"><a href="ipc.html" >Networking and Interprocess Communication</a> &#187;</li>187          <li class="nav-item nav-item-3"><a href="asyncio.html" accesskey="U"><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code> — Asynchronous I/O</a> &#187;</li>188        <li class="nav-item nav-item-this"><a href="">Call Graph Introspection</a></li>189                <li class="right">190                    191 192    <div class="inline-search" role="search">193        <form class="inline-search" action="../search.html" method="get">194          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">195          <input type="submit" value="Go">196        </form>197    </div>198                     |199                </li>200            <li class="right">201<label class="theme-selector-label">202    Theme203    <select class="theme-selector" oninput="activateTheme(this.value)">204        <option value="auto" selected>Auto</option>205        <option value="light">Light</option>206        <option value="dark">Dark</option>207    </select>208</label> |</li>209            210      </ul>211    </div>    212 213    <div class="document">214      <div class="documentwrapper">215        <div class="bodywrapper">216          <div class="body" role="main">217            218  <section id="call-graph-introspection">219<span id="asyncio-graph"></span><h1>Call Graph Introspection<a class="headerlink" href="#call-graph-introspection" title="Link to this heading">¶</a></h1>220<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/asyncio/graph.py">Lib/asyncio/graph.py</a></p>221<hr class="docutils" />222<p>asyncio has powerful runtime call graph introspection utilities223to trace the entire call graph of a running <em>coroutine</em> or <em>task</em>, or224a suspended <em>future</em>.  These utilities and the underlying machinery225can be used from within a Python program or by external profilers226and debuggers.</p>227<div class="versionadded">228<p><span class="versionmodified added">Added in version 3.14.</span></p>229</div>230<dl class="py function">231<dt class="sig sig-object py" id="asyncio.print_call_graph">232<span class="sig-prename descclassname"><span class="pre">asyncio.</span></span><span class="sig-name descname"><span class="pre">print_call_graph</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">future</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="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</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">depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#asyncio.print_call_graph" title="Link to this definition">¶</a></dt>233<dd><p>Print the async call graph for the current task or the provided234<a class="reference internal" href="asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> or <a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a>.</p>235<p>This function prints entries starting from the top frame and going236down towards the invocation point.</p>237<p>The function receives an optional <em>future</em> argument.238If not passed, the current running task will be used.</p>239<p>If the function is called on <em>the current task</em>, the optional240keyword-only <em>depth</em> argument can be used to skip the specified241number of frames from top of the stack.</p>242<p>If the optional keyword-only <em>limit</em> argument is provided, each call stack243in the resulting graph is truncated to include at most <code class="docutils literal notranslate"><span class="pre">abs(limit)</span></code>244entries. If <em>limit</em> is positive, the entries left are the closest to245the invocation point. If <em>limit</em> is negative, the topmost entries are246left. If <em>limit</em> is omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, all entries are present.247If <em>limit</em> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, the call stack is not printed at all, only248“awaited by” information is printed.</p>249<p>If <em>file</em> is omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, the function will print250to <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>.</p>251<p><strong>Example:</strong></p>252<p>The following Python code:</p>253<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">asyncio</span>254 255<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">test</span><span class="p">():</span>256    <span class="n">asyncio</span><span class="o">.</span><span class="n">print_call_graph</span><span class="p">()</span>257 258<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">main</span><span class="p">():</span>259    <span class="k">async</span> <span class="k">with</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TaskGroup</span><span class="p">()</span> <span class="k">as</span> <span class="n">g</span><span class="p">:</span>260        <span class="n">g</span><span class="o">.</span><span class="n">create_task</span><span class="p">(</span><span class="n">test</span><span class="p">(),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;test&#39;</span><span class="p">)</span>261 262<span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>263</pre></div>264</div>265<p>will print:</p>266<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">*</span> <span class="n">Task</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;test&#39;</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mh">0x1039f0fe0</span><span class="p">)</span>267<span class="o">+</span> <span class="n">Call</span> <span class="n">stack</span><span class="p">:</span>268<span class="o">|</span>   <span class="n">File</span> <span class="s1">&#39;t2.py&#39;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">4</span><span class="p">,</span> <span class="ow">in</span> <span class="k">async</span> <span class="n">test</span><span class="p">()</span>269<span class="o">+</span> <span class="n">Awaited</span> <span class="n">by</span><span class="p">:</span>270   <span class="o">*</span> <span class="n">Task</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;Task-1&#39;</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mh">0x103a5e060</span><span class="p">)</span>271      <span class="o">+</span> <span class="n">Call</span> <span class="n">stack</span><span class="p">:</span>272      <span class="o">|</span>   <span class="n">File</span> <span class="s1">&#39;taskgroups.py&#39;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">107</span><span class="p">,</span> <span class="ow">in</span> <span class="k">async</span> <span class="n">TaskGroup</span><span class="o">.</span><span class="fm">__aexit__</span><span class="p">()</span>273      <span class="o">|</span>   <span class="n">File</span> <span class="s1">&#39;t2.py&#39;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">7</span><span class="p">,</span> <span class="ow">in</span> <span class="k">async</span> <span class="n">main</span><span class="p">()</span>274</pre></div>275</div>276</dd></dl>277 278<dl class="py function">279<dt class="sig sig-object py" id="asyncio.format_call_graph">280<span class="sig-prename descclassname"><span class="pre">asyncio.</span></span><span class="sig-name descname"><span class="pre">format_call_graph</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">future</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="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#asyncio.format_call_graph" title="Link to this definition">¶</a></dt>281<dd><p>Like <a class="reference internal" href="#asyncio.print_call_graph" title="asyncio.print_call_graph"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_call_graph()</span></code></a>, but returns a string.282If <em>future</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code> and there’s no current task,283the function returns an empty string.</p>284</dd></dl>285 286<dl class="py function">287<dt class="sig sig-object py" id="asyncio.capture_call_graph">288<span class="sig-prename descclassname"><span class="pre">asyncio.</span></span><span class="sig-name descname"><span class="pre">capture_call_graph</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">future</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="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#asyncio.capture_call_graph" title="Link to this definition">¶</a></dt>289<dd><p>Capture the async call graph for the current task or the provided290<a class="reference internal" href="asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> or <a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a>.</p>291<p>The function receives an optional <em>future</em> argument.292If not passed, the current running task will be used. If there’s no293current task, the function returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>294<p>If the function is called on <em>the current task</em>, the optional295keyword-only <em>depth</em> argument can be used to skip the specified296number of frames from top of the stack.</p>297<p>Returns a <code class="docutils literal notranslate"><span class="pre">FutureCallGraph</span></code> data class object:</p>298<ul>299<li><p><code class="docutils literal notranslate"><span class="pre">FutureCallGraph(future,</span> <span class="pre">call_stack,</span> <span class="pre">awaited_by)</span></code></p>300<blockquote>301<div><p>Where <em>future</em> is a reference to a <a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a> or302a <a class="reference internal" href="asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> (or their subclasses.)</p>303<p><code class="docutils literal notranslate"><span class="pre">call_stack</span></code> is a tuple of <code class="docutils literal notranslate"><span class="pre">FrameCallGraphEntry</span></code> objects.</p>304<p><code class="docutils literal notranslate"><span class="pre">awaited_by</span></code> is a tuple of <code class="docutils literal notranslate"><span class="pre">FutureCallGraph</span></code> objects.</p>305</div></blockquote>306</li>307<li><p><code class="docutils literal notranslate"><span class="pre">FrameCallGraphEntry(frame)</span></code></p>308<blockquote>309<div><p>Where <em>frame</em> is a frame object of a regular Python function310in the call stack.</p>311</div></blockquote>312</li>313</ul>314</dd></dl>315 316<section id="low-level-utility-functions">317<h2>Low level utility functions<a class="headerlink" href="#low-level-utility-functions" title="Link to this heading">¶</a></h2>318<p>To introspect an async call graph asyncio requires cooperation from319control flow structures, such as <a class="reference internal" href="asyncio-task.html#asyncio.shield" title="asyncio.shield"><code class="xref py py-func docutils literal notranslate"><span class="pre">shield()</span></code></a> or <a class="reference internal" href="asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a>.320Any time an intermediate <a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a> object with low-level APIs like321<a class="reference internal" href="asyncio-future.html#asyncio.Future.add_done_callback" title="asyncio.Future.add_done_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Future.add_done_callback()</span></code></a> is322involved, the following two functions should be used to inform asyncio323about how exactly such intermediate future objects are connected with324the tasks they wrap or control.</p>325<dl class="py function">326<dt class="sig sig-object py" id="asyncio.future_add_to_awaited_by">327<span class="sig-prename descclassname"><span class="pre">asyncio.</span></span><span class="sig-name descname"><span class="pre">future_add_to_awaited_by</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">future</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">waiter</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="#asyncio.future_add_to_awaited_by" title="Link to this definition">¶</a></dt>328<dd><p>Record that <em>future</em> is awaited on by <em>waiter</em>.</p>329<p>Both <em>future</em> and <em>waiter</em> must be instances of330<a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a> or <a class="reference internal" href="asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> or their subclasses,331otherwise the call would have no effect.</p>332<p>A call to <code class="docutils literal notranslate"><span class="pre">future_add_to_awaited_by()</span></code> must be followed by an333eventual call to the <a class="reference internal" href="#asyncio.future_discard_from_awaited_by" title="asyncio.future_discard_from_awaited_by"><code class="xref py py-func docutils literal notranslate"><span class="pre">future_discard_from_awaited_by()</span></code></a> function334with the same arguments.</p>335</dd></dl>336 337<dl class="py function">338<dt class="sig sig-object py" id="asyncio.future_discard_from_awaited_by">339<span class="sig-prename descclassname"><span class="pre">asyncio.</span></span><span class="sig-name descname"><span class="pre">future_discard_from_awaited_by</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">future</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">waiter</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="#asyncio.future_discard_from_awaited_by" title="Link to this definition">¶</a></dt>340<dd><p>Record that <em>future</em> is no longer awaited on by <em>waiter</em>.</p>341<p>Both <em>future</em> and <em>waiter</em> must be instances of342<a class="reference internal" href="asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a> or <a class="reference internal" href="asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> or their subclasses, otherwise343the call would have no effect.</p>344</dd></dl>345 346</section>347</section>348 349 350            <div class="clearer"></div>351          </div>352        </div>353      </div>354      <div class="sphinxsidebar" role="navigation" aria-label="Main">355        <div class="sphinxsidebarwrapper">356  <div>357    <h3><a href="../contents.html">Table of Contents</a></h3>358    <ul>359<li><a class="reference internal" href="#">Call Graph Introspection</a><ul>360<li><a class="reference internal" href="#low-level-utility-functions">Low level utility functions</a></li>361</ul>362</li>363</ul>364 365  </div>366  <div>367    <h4>Previous topic</h4>368    <p class="topless"><a href="asyncio-exceptions.html"369                          title="previous chapter">Exceptions</a></p>370  </div>371  <div>372    <h4>Next topic</h4>373    <p class="topless"><a href="asyncio-eventloop.html"374                          title="next chapter">Event Loop</a></p>375  </div>376  <script>377    document.addEventListener('DOMContentLoaded', () => {378        const title = document.querySelector('meta[property="og:title"]').content;379        const elements = document.querySelectorAll('.improvepage');380        const pageurl = window.location.href.split('?')[0];381        elements.forEach(element => {382            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));383            url.searchParams.set('pagetitle', title);384            url.searchParams.set('pageurl', pageurl);385            url.searchParams.set('pagesource', "library/asyncio-graph.rst");386            element.href = url.toString();387        });388    });389  </script>390  <div role="note" aria-label="source link">391    <h3>This page</h3>392    <ul class="this-page-menu">393      <li><a href="../bugs.html">Report a bug</a></li>394      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>395      <li>396        <a href="https://github.com/python/cpython/blob/main/Doc/library/asyncio-graph.rst?plain=1"397            rel="nofollow">Show source398        </a>399      </li>400      401    </ul>402  </div>403        </div>404<div id="sidebarbutton" title="Collapse sidebar">405<span>«</span>406</div>407 408      </div>409      <div class="clearer"></div>410    </div>  411    <div class="related" role="navigation" aria-label="Related">412      <h3>Navigation</h3>413      <ul>414        <li class="right" style="margin-right: 10px">415          <a href="../genindex.html" title="General Index"416             >index</a></li>417        <li class="right" >418          <a href="../py-modindex.html" title="Python Module Index"419             >modules</a> |</li>420        <li class="right" >421          <a href="asyncio-eventloop.html" title="Event Loop"422             >next</a> |</li>423        <li class="right" >424          <a href="asyncio-exceptions.html" title="Exceptions"425             >previous</a> |</li>426 427          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>428          <li><a href="https://www.python.org/">Python</a> &#187;</li>429          <li class="switchers">430            <div class="language_switcher_placeholder"></div>431            <div class="version_switcher_placeholder"></div>432          </li>433          <li>434              435          </li>436    <li id="cpython-language-and-version">437      <a href="../index.html">3.15.0a6 Documentation</a> &#187;438    </li>439 440          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>441          <li class="nav-item nav-item-2"><a href="ipc.html" >Networking and Interprocess Communication</a> &#187;</li>442          <li class="nav-item nav-item-3"><a href="asyncio.html" ><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code> — Asynchronous I/O</a> &#187;</li>443        <li class="nav-item nav-item-this"><a href="">Call Graph Introspection</a></li>444                <li class="right">445                    446 447    <div class="inline-search" role="search">448        <form class="inline-search" action="../search.html" method="get">449          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">450          <input type="submit" value="Go">451        </form>452    </div>453                     |454                </li>455            <li class="right">456<label class="theme-selector-label">457    Theme458    <select class="theme-selector" oninput="activateTheme(this.value)">459        <option value="auto" selected>Auto</option>460        <option value="light">Light</option>461        <option value="dark">Dark</option>462    </select>463</label> |</li>464            465      </ul>466    </div>  467    <div class="footer">468    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.469    <br>470    This page is licensed under the Python Software Foundation License Version 2.471    <br>472    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.473    <br>474    475      See <a href="/license.html">History and License</a> for more information.<br>476    477    478    <br>479 480    The Python Software Foundation is a non-profit corporation.481<a href="https://www.python.org/psf/donations/">Please donate.</a>482<br>483    <br>484      Last updated on Mar 10, 2026 (08:58 UTC).485    486      <a href="/bugs.html">Found a bug</a>?487    488    <br>489 490    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.491    </div>492 493  </body>494</html>