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.

Title: Example for Profile Module shows incorrect method
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: arigo, dmi.baranov, docs@python, ezio.melotti, jough, ohe, orsenthil, pconnell, python-dev
Priority: normal Keywords: easy, patch

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

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:


import cProfile, pstats, io
pr = cProfile.Profile()
... do something ...
s = io.StringIO()
ps = pstats.Stats(pr, stream=s)

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
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:
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 .

New changeset ab4d3ccb92e6 by Senthil Kumaran in branch '3.3':
Correct Profile class usage example. Addresses issue #18033.

New changeset 88182b388bae by Senthil Kumaran in branch 'default':
merge from 3.3
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.
Date User Action Args
2022-04-11 14:57:45adminsetgithub: 62233
2013-09-08 00:53:55orsenthilsetstatus: open -> closed

nosy: + orsenthil
messages: + msg197209

resolution: fixed
stage: patch review -> resolved
2013-09-08 00:52:47python-devsetnosy: + python-dev
messages: + msg197208
2013-07-03 17:24:13ohesetfiles: + issue18033_py2.patch
nosy: + ohe
messages: + msg192246

2013-06-11 09:46:41arigosetnosy: + arigo
messages: + msg190954
2013-06-08 20:26:52ezio.melottisetstage: needs patch -> patch review
messages: + msg190823
versions: + Python 3.3
2013-06-06 09:40:47r.david.murraylinkissue18146 superseder
2013-05-27 20:42:59dmi.baranovsetfiles: + issue18033_py2.patch

messages: + msg190154
2013-05-27 20:42:41dmi.baranovsetfiles: + issue18033_py3.patch
versions: + Python 3.4
nosy: + dmi.baranov

messages: + msg190153

keywords: + patch
2013-05-26 13:44:25ezio.melottisetkeywords: + easy
nosy: + ezio.melotti

stage: needs patch
2013-05-25 09:10:12pconnellsetnosy: + pconnell
2013-05-22 15:12:38joughcreate