Issue29235
Created on 2017-01-11 01:13 by Thane Brimhall, last changed 2019-01-29 13:26 by cheryl.sabella. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| profileContextManager.patch | Thane Brimhall, 2017-01-16 03:35 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 6808 | merged | python-dev, 2018-05-14 16:10 | |
| PR 7331 | merged | Scott Sanderson, 2018-06-01 22:27 | |
| Messages (10) | |||
|---|---|---|---|
| msg285175 - (view) | Author: Thane Brimhall (Thane Brimhall) * | Date: 2017-01-11 01:13 | |
The `enable` and `disable` methods on the profilers fit the description of a context manager very well. The following code:
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()
|
|||
| msg285535 - (view) | Author: Thane Brimhall (Thane Brimhall) * | Date: 2017-01-16 03:35 | |
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? |
|||
| msg285536 - (view) | Author: Xiang Zhang (xiang.zhang) * | Date: 2017-01-16 03:40 | |
> 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/. :-) |
|||
| msg285538 - (view) | Author: Thane Brimhall (Thane Brimhall) * | Date: 2017-01-16 03:53 | |
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 `profile` was a stated goal, it turns out that the pure-python profiler actually does not have the enable() and disable() methods that the context manager needs. |
|||
| msg316533 - (view) | Author: Scott Sanderson (Scott Sanderson) * | Date: 2018-05-14 16:19 | |
This looks like it's been dormant for a bit. I've posted a patch (with tests and docs) to https://github.com/python/cpython/pull/6808. |
|||
| msg318459 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2018-06-01 20:36 | |
New changeset 2e01b75884892d5aabdaab658fbd17f7a7ccebaa by Brett Cannon (Scott Sanderson) in branch 'master': bpo-29235: Make cProfile.Profile a context manager (GH-6808) https://github.com/python/cpython/commit/2e01b75884892d5aabdaab658fbd17f7a7ccebaa |
|||
| msg318460 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2018-06-01 20:42 | |
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. |
|||
| msg318471 - (view) | Author: Scott Sanderson (Scott Sanderson2) | Date: 2018-06-01 22:29 | |
I've posted a patch to update the docs to https://github.com/python/cpython/pull/7331. |
|||
| msg318917 - (view) | Author: Inada Naoki (methane) * | Date: 2018-06-07 09:46 | |
New changeset cebe80b59b7386db3cce904d280dab61d1037e7a by INADA Naoki (Scott Sanderson) in branch 'master': bpo-29235: Update document for Profiler's context manager (GH-7331) https://github.com/python/cpython/commit/cebe80b59b7386db3cce904d280dab61d1037e7a |
|||
| msg334514 - (view) | Author: Cheryl Sabella (cheryl.sabella) * | Date: 2019-01-29 13:26 | |
Closing as these changes have been merged for a few months. msg285538 mentions that the pure-Python profiler doesn't have `enable` and `disable`, which is already opened in issue 32017. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019-01-29 13:26:26 | cheryl.sabella | set | status: open -> closed nosy:
+ cheryl.sabella resolution: fixed |
| 2018-06-07 09:46:45 | methane | set | nosy:
+ methane messages: + msg318917 |
| 2018-06-01 22:29:25 | Scott Sanderson2 | set | nosy:
+ Scott Sanderson2 messages: + msg318471 |
| 2018-06-01 22:27:21 | Scott Sanderson | set | pull_requests: + pull_request6961 |
| 2018-06-01 20:42:58 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages:
+ msg318460 |
| 2018-06-01 20:36:26 | brett.cannon | set | nosy:
+ brett.cannon messages: + msg318459 |
| 2018-05-14 16:19:48 | Scott Sanderson | set | nosy:
+ Scott Sanderson messages: + msg316533 |
| 2018-05-14 16:10:15 | python-dev | set | stage: test needed -> patch review pull_requests: + pull_request6495 |
| 2017-01-16 03:53:46 | Thane Brimhall | set | messages: + msg285538 |
| 2017-01-16 03:40:42 | xiang.zhang | set | nosy:
+ xiang.zhang messages:
+ msg285536 |
| 2017-01-16 03:35:34 | Thane Brimhall | set | files:
+ profileContextManager.patch keywords: + patch messages: + msg285535 |
| 2017-01-11 03:52:29 | ethan.furman | set | nosy:
+ ethan.furman stage: needs patch |
| 2017-01-11 01:13:40 | Thane Brimhall | create | |