This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Thane Brimhall
Recipients Thane Brimhall
Date 2017-01-11.01:13:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484097220.43.0.363931456874.issue29235@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2017-01-11 01:13:40Thane Brimhallsetrecipients: + Thane Brimhall
2017-01-11 01:13:40Thane Brimhallsetmessageid: <1484097220.43.0.363931456874.issue29235@psf.upfronthosting.co.za>
2017-01-11 01:13:40Thane Brimhalllinkissue29235 messages
2017-01-11 01:13:40Thane Brimhallcreate