Skip to content

Commit 0774805

Browse files
committed
Rename "asyncio.stack" to "asyncio.graph"
1 parent 9f04911 commit 0774805

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

Doc/library/asyncio-stack.rst renamed to Doc/library/asyncio-graph.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
.. currentmodule:: asyncio
22

33

4-
.. _asyncio-stack:
4+
.. _asyncio-graph:
55

66
===================
77
Stack Introspection
88
===================
99

10-
**Source code:** :source:`Lib/asyncio/stack.py`
10+
**Source code:** :source:`Lib/asyncio/graph.py`
1111

1212
-------------------------------------
1313

14-
asyncio has powerful runtime call stack introspection utilities
14+
asyncio has powerful runtime call graph introspection utilities
1515
to trace the entire call graph of a running coroutine or task, or
1616
a suspended *future*. These utilities and the underlying machinery
1717
can be used by users in their Python code or by external profilers

Doc/library/asyncio.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You can experiment with an ``asyncio`` concurrent context in the :term:`REPL`:
9999
asyncio-subprocess.rst
100100
asyncio-queue.rst
101101
asyncio-exceptions.rst
102-
asyncio-stack.rst
102+
asyncio-graph.rst
103103

104104
.. toctree::
105105
:caption: Low-level APIs

Lib/asyncio/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .protocols import *
1515
from .runners import *
1616
from .queues import *
17-
from .stack import *
17+
from .graph import *
1818
from .streams import *
1919
from .subprocess import *
2020
from .tasks import *
@@ -32,7 +32,7 @@
3232
protocols.__all__ +
3333
runners.__all__ +
3434
queues.__all__ +
35-
stack.__all__ +
35+
graph.__all__ +
3636
streams.__all__ +
3737
subprocess.__all__ +
3838
tasks.__all__ +

Lib/asyncio/stack.py renamed to Lib/asyncio/graph.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Introspection utils for tasks call stacks."""
1+
"""Introspection utils for tasks call graphs."""
22

33
import dataclasses
44
import sys
@@ -18,7 +18,7 @@
1818

1919
# Sadly, we can't re-use the traceback's module datastructures as those
2020
# are tailored for error reporting, whereas we need to represent an
21-
# async call stack.
21+
# async call graph.
2222
#
2323
# Going with pretty verbose names as we'd like to export them to the
2424
# top level asyncio namespace, and want to avoid future name clashes.
@@ -36,7 +36,7 @@ class FutureCallGraph:
3636
awaited_by: list[FutureCallGraph]
3737

3838

39-
def _build_stack_for_future(future: futures.Future) -> FutureCallGraph:
39+
def _build_graph_for_future(future: futures.Future) -> FutureCallGraph:
4040
if not isinstance(future, futures.Future):
4141
raise TypeError(
4242
f"{future!r} object does not appear to be compatible "
@@ -64,7 +64,7 @@ def _build_stack_for_future(future: futures.Future) -> FutureCallGraph:
6464

6565
if future._asyncio_awaited_by:
6666
for parent in future._asyncio_awaited_by:
67-
awaited_by.append(_build_stack_for_future(parent))
67+
awaited_by.append(_build_graph_for_future(parent))
6868

6969
st.reverse()
7070
return FutureCallGraph(future, st, awaited_by)
@@ -75,9 +75,9 @@ def capture_call_graph(
7575
future: futures.Future | None = None,
7676
depth: int = 1,
7777
) -> FutureCallGraph | None:
78-
"""Capture async call stack for the current task or the provided Future.
78+
"""Capture async call graph for the current task or the provided Future.
7979
80-
The stack is represented with three data structures:
80+
The graph is represented with three data structures:
8181
8282
* FutureCallGraph(future, call_stack, awaited_by)
8383
@@ -109,7 +109,7 @@ def capture_call_graph(
109109
# if yes - check if the passed future is the currently
110110
# running task or not.
111111
if loop is None or future is not tasks.current_task(loop=loop):
112-
return _build_stack_for_future(future)
112+
return _build_graph_for_future(future)
113113
# else: future is the current task, move on.
114114
else:
115115
if loop is None:
@@ -151,7 +151,7 @@ def capture_call_graph(
151151
awaited_by = []
152152
if future._asyncio_awaited_by:
153153
for parent in future._asyncio_awaited_by:
154-
awaited_by.append(_build_stack_for_future(parent))
154+
awaited_by.append(_build_graph_for_future(parent))
155155

156156
return FutureCallGraph(future, call_stack, awaited_by)
157157

@@ -162,7 +162,7 @@ def print_call_graph(
162162
file: typing.TextIO | None = None,
163163
depth: int = 1,
164164
) -> None:
165-
"""Print async call stack for the current task or the provided Future."""
165+
"""Print async call graph for the current task or the provided Future."""
166166

167167
def render_level(st: FutureCallGraph, buf: list[str], level: int) -> None:
168168
def add_line(line: str) -> None:
@@ -221,16 +221,16 @@ def add_line(line: str) -> None:
221221
for fut in st.awaited_by:
222222
render_level(fut, buf, level + 1)
223223

224-
stack = capture_call_graph(future=future, depth=depth + 1)
225-
if stack is None:
224+
graph = capture_call_graph(future=future, depth=depth + 1)
225+
if graph is None:
226226
return
227227

228228
try:
229229
buf: list[str] = []
230-
render_level(stack, buf, 0)
230+
render_level(graph, buf, 0)
231231
rendered = '\n'.join(buf)
232232
print(rendered, file=file)
233233
finally:
234-
# 'stack' has references to frames so we should
234+
# 'graph' has references to frames so we should
235235
# make sure it's GC'ed as soon as we don't need it.
236-
del stack
236+
del graph

0 commit comments

Comments
 (0)