[Python-ideas] Allow Profile() to be used as a context manager

Yuval Greenfield ubershmekel at gmail.com
Wed Jan 25 09:19:33 CET 2012

On Wed, Jan 25, 2012 at 8:36 AM, David Townshend <aquavitae69 at gmail.com>wrote:

> [...]
> Any major objections to this?

 At first this sounded like a good idea but 2 things pop to mind:

   1. How does one get the pstat profiling output from the context manager?
   Will printing out the results be the only option?
   2. Usually when I profile I don't want to touch the code at all so
   eventually if I'll use this context manager it'll be more akin to

    with profile.Profiler():

Which isn't much of a win over


Now if you're talking about a reentrant profiler, that's interesting:

    profiler = profile.Profiler()

    while is_working:
        with profiler:


    with profiler:

and then I can call whatever method is there to get the pstat. If this is
the vision then it sounds awesome.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120125/2124b024/attachment.html>

More information about the Python-ideas mailing list