diff options
author | Scott Sanderson <ssanderson@quantopian.com> | 2018-06-01 20:36:23 (GMT) |
---|---|---|
committer | Brett Cannon <brettcannon@users.noreply.github.com> | 2018-06-01 20:36:23 (GMT) |
commit | 2e01b75884892d5aabdaab658fbd17f7a7ccebaa (patch) | |
tree | 2f518fe2d3d32e398d5ddbf3d10681f2396f4e3c /Lib/cProfile.py | |
parent | 252f6abe0a9430f4ae7588c0cb50a6ff141bebe3 (diff) | |
download | cpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.zip cpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.tar.gz cpython-2e01b75884892d5aabdaab658fbd17f7a7ccebaa.tar.bz2 |
bpo-29235: Make cProfile.Profile a context manager (GH-6808)
Diffstat (limited to 'Lib/cProfile.py')
-rwxr-xr-x | Lib/cProfile.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py index f166a1c..c804504 100755 --- a/Lib/cProfile.py +++ b/Lib/cProfile.py @@ -110,6 +110,13 @@ class Profile(_lsprof.Profiler): finally: self.disable() + def __enter__(self): + self.enable() + return self + + def __exit__(self, *exc_info): + self.disable() + # ____________________________________________________________ def label(code): |