summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorScott Sanderson <ssanderson@quantopian.com>2018-06-01 20:36:23 (GMT)
committerBrett Cannon <brettcannon@users.noreply.github.com>2018-06-01 20:36:23 (GMT)
commit2e01b75884892d5aabdaab658fbd17f7a7ccebaa (patch)
tree2f518fe2d3d32e398d5ddbf3d10681f2396f4e3c /Doc/library
parent252f6abe0a9430f4ae7588c0cb50a6ff141bebe3 (diff)
downloadcpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.zip
cpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.tar.gz
cpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.tar.bz2
bpo-29235: Make cProfile.Profile a context manager (GH-6808)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/profile.rst10
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst
index a6dc56f..5dc0b2f 100644
--- a/Doc/library/profile.rst
+++ b/Doc/library/profile.rst
@@ -262,6 +262,16 @@ functions:
ps.print_stats()
print(s.getvalue())
+ The :class:`Profile` class can also be used as a context manager (see
+ :ref:`typecontextmanager`)::
+
+ import cProfile
+
+ with cProfile.Profile() as pr:
+ # ... do something ...
+
+ pr.print_stats()
+
.. method:: enable()
Start collecting profiling data.