A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/061844.html below:

[Python-Dev] cProfile prints to stdout?

[Python-Dev] cProfile prints to stdout? [Python-Dev] cProfile prints to stdout?Guido van Rossum gvanrossum at gmail.com
Sun Feb 26 18:12:25 CET 2006
On 2/25/06, skip at pobox.com <skip at pobox.com> wrote:
>
>     >> It is currently impossible to separate profile output from the
>     >> program's output.
>
>     Guido> It is if you use the "advanced" use of the profiler -- the
>     Guido> profiling run just saves the profiling data to a file, and the
>     Guido> pstats module invoked separately prints the output.
>
> Sure, but then it's not "simple".  Your original example was "... > file".
> I'd like it to be (nearly) as easy to do it right yet keep it simple.

OK. I believe the default should be stdout though, and the conveniece
method print_stats() in profile.py should be the only place that
references stderr. The smallest code mod would be to redirect stdout
temporarily inside print_stats(); but I won't complain if you're more
ambitious and modify pstats.py.

    def print_stats(self, sort=-1, stream=None):
        import pstats
        if stream is None:
            stream = sys.stderr
        save = sys.stdout
        try:
            if stream is not None:
                sys.stdout = stream
            pstats.Stats(self).strip_dirs().sort_stats(sort). \
                  print_stats()
        finally:
            sys.stdout = save

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4