[Python-ideas] Allow Profile() to be used as a context manager
Nick Coghlan
ncoghlan at gmail.com
Wed Jan 25 11:24:39 CET 2012
On Wed, Jan 25, 2012 at 7:47 PM, David Townshend <aquavitae69 at gmail.com> wrote:
> The same way as currently:
>
> profile = cProfile.Profile()
> with profile:
> do_something()
>
> profile.dump_stats(filename)
If __enter__() returns self (as is recommended when you don't have
anything more context specific to return), then the following would
also work:
with cProfile.Profile() as profile:
do_something()
profile.dump_stats(filename)
Assuming the re-entrancy question can be answered adequately, this
sounds like a reasonable idea to me.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list