-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow profile/cProfile to be used as context managers #73421
Comments
The pr = cProfile.Profile()
pr.enable()
# ... do something ...
pr.disable()
pr.print_stats() Would turn into something like this: with cProfile.Profile() as pr:
# ... do something ...
pr.print_stats() The patch for this code would be trivial and backwards-compatible: simply add something like the following lines to the _lsprof.Profiler base class: def __enter__(self):
self.enable()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.disable() |
So this is my first time contributing to Python, but here's a (trivial) patch for this issue. Let me know what else is required to make this happen. I suspect unit tests and documentation updates? |
Yes. Code alone is not enough. It's better to have tests and documentation. Also, it's appreciated to sign the CLA: https://www.python.org/psf/contrib/contrib-form/. :-) |
I've signed the agreement. I will do the necessary research to figure out how to do unit tests and documentation updates. I should also mention that while maintaining API-compatibility with |
This looks like it's been dormant for a bit. I've posted a patch (with tests and docs) to #6808. |
Please add a versionadded or versionchanged directive in the documentation (not sure what is more appropriate in this case) and an entry in What's New. A news entry shouldn't consist of several paragraphs. This will be lost when news entries will be merged into a single NEWS file. |
I've posted a patch to update the docs to #7331. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: