Issue 18033: Example for Profile Module shows incorrect method (original) (raw)

Issue18033

Created on 2013-05-22 15:12 by jough, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue18033_py3.patch dmi.baranov,2013-05-27 20:42 review
issue18033_py2.patch dmi.baranov,2013-05-27 20:42 review
issue18033_py2.patch ohe,2013-07-03 17:24 review
Messages (8)
msg189823 - (view) Author: Jough Dempsey (jough) Date: 2013-05-22 15:12
The example on this page: http://docs.python.org/2/library/profile.html?highlight=pstats#profile.Profile Shows: import cProfile, pstats, io pr = cProfile.Profile() pr.enable() ... do something ... pr.disable() s = io.StringIO() ps = pstats.Stats(pr, stream=s) ps.print_results() Where "ps.print_results()" should be "ps.print_stats()"
msg190153 - (view) Author: Dmi Baranov (dmi.baranov) * Date: 2013-05-27 20:42
Added py3 patch
msg190154 - (view) Author: Dmi Baranov (dmi.baranov) * Date: 2013-05-27 20:42
py2
msg190823 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-06-08 20:26
Thanks for the patches, however the Python 2 example doesn't work. I think a BytesIO should be used instead of a StringIO, and print_stats() only returns a pstats.Stats instance, without actually printing any result. I wonder if print_results was an old method that has been removed and if now there's another way to print the results. I haven't tried on Python 3 yet, but the same comment might apply there too.
msg190954 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2013-06-11 09:46
A slightly more complete example that I tested: http://stackoverflow.com/a/16077568/1556290
msg192246 - (view) Author: Olivier Hervieu (ohe) Date: 2013-07-03 17:24
Here is a fixed version for python2.7. Using StringIO instead of io module fixes the problem pointed by Ezio. The print_stats method dumps the stats either on sys.stdout if `Stats` class is declared without a stream specification or in the given stream parameter (the name print_stats may be a bit misleading).
msg197208 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-09-08 00:52
New changeset 93018d47793f by Senthil Kumaran in branch '2.7': Correct Profile class usage example. Addresses issue #18033 . http://hg.python.org/cpython/rev/93018d47793f New changeset ab4d3ccb92e6 by Senthil Kumaran in branch '3.3': Correct Profile class usage example. Addresses issue #18033. http://hg.python.org/cpython/rev/ab4d3ccb92e6 New changeset 88182b388bae by Senthil Kumaran in branch 'default': merge from 3.3 http://hg.python.org/cpython/rev/88182b388bae
msg197209 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2013-09-08 00:53
I consolidated the patches and example and have committed them to 2.7, 3.3 and 3.4. Thanks for your contributions.
History
Date User Action Args
2022-04-11 14:57:45 admin set github: 62233
2013-09-08 00:53:55 orsenthil set status: open -> closednosy: + orsenthilmessages: + resolution: fixedstage: patch review -> resolved
2013-09-08 00:52:47 python-dev set nosy: + python-devmessages: +
2013-07-03 17:24:13 ohe set files: + issue18033_py2.patchnosy: + ohemessages: +
2013-06-11 09:46:41 arigo set nosy: + arigomessages: +
2013-06-08 20:26:52 ezio.melotti set stage: needs patch -> patch reviewmessages: + versions: + Python 3.3
2013-06-06 09:40:47 r.david.murray link issue18146 superseder
2013-05-27 20:42:59 dmi.baranov set files: + issue18033_py2.patchmessages: +
2013-05-27 20:42:41 dmi.baranov set files: + issue18033_py3.patchversions: + Python 3.4nosy: + dmi.baranovmessages: + keywords: + patch
2013-05-26 13:44:25 ezio.melotti set keywords: + easynosy: + ezio.melottistage: needs patch
2013-05-25 09:10:12 pconnell set nosy: + pconnell
2013-05-22 15:12:38 jough create