Skip to content

Commit

Permalink
Fixed the usage of pstats.Stats() output stream. The
Browse files Browse the repository at this point in the history
Control_Panel/DebugInfo/manage_profile ZMI view has been broken since
Python 2.5.  This breaks Python 2.4 compatibility when the
publisher-profile-file configuration option is set.  This also removes
some ugly sys.stdout hackery.
  • Loading branch information
rpatterson committed Nov 18, 2010
1 parent e4816be commit 5f72af2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 4 additions & 0 deletions doc/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed
++++++++++

- Fixed the usage of pstats.Stats() output stream. The
Control_Panel/DebugInfo/manage_profile ZMI view has been broken
since Python 2.5. This breaks Python 2.4 compatibility when the
publisher-profile-file configuration option is set.


2.12.13 (2010-11-06)
Expand Down
8 changes: 1 addition & 7 deletions src/App/ApplicationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
__version__='$Revision: 1.94 $'[11:-2]

from cgi import escape
from cStringIO import StringIO
from logging import getLogger
import os
import sys
Expand Down Expand Up @@ -232,17 +231,12 @@ def manage_profile_stats(self, sort='time', limit=200, stripDirs=1, mode='stats'
stats=getattr(sys, '_ps_', None)
if stats is None:
return None
output=StringIO()
stdout=sys.stdout
if stripDirs:
from copy import copy; stats= copy(stats)
stats.strip_dirs()
stats.sort_stats(sort)
sys.stdout=output
getattr(stats,'print_%s' % mode)(limit)
sys.stdout.flush()
sys.stdout=stdout
return output.getvalue()
return stats.stream.getvalue()

def manage_getSysPath(self):
return list(sys.path)
Expand Down
4 changes: 3 additions & 1 deletion src/ZPublisher/Publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def publish_module_profiled(module_name, stdin=sys.stdin, stdout=sys.stdout,
result=sys._pr_
pobj.create_stats()
if _pstat is None:
_pstat=sys._ps_=pstats.Stats(pobj)
from cStringIO import StringIO
stream = StringIO()
_pstat = sys._ps_ = pstats.Stats(pobj, stream=stream)
else: _pstat.add(pobj)
finally:
_plock.release()
Expand Down

0 comments on commit 5f72af2

Please sign in to comment.