Message285175
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() |
|
| Date |
User |
Action |
Args |
| 2017-01-11 01:13:40 | Thane Brimhall | set | recipients:
+ Thane Brimhall |
| 2017-01-11 01:13:40 | Thane Brimhall | set | messageid: <[email protected]> |
| 2017-01-11 01:13:40 | Thane Brimhall | link | issue29235 messages |
| 2017-01-11 01:13:40 | Thane Brimhall | create | |
|