Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1985

Show
Ignore:
Timestamp:
06/22/08 19:32:32
Author:
fumanchu
Message:

Fix for #827 (Profile viewer doesn't work with Python2.5).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/profiler.py

    r1819 r1985  
    9595    def stats(self, filename, sortby='cumulative'): 
    9696        """stats(index) -> output of print_stats() for the given profile.""" 
    97         s = pstats.Stats(os.path.join(self.path, filename)) 
    98         s.strip_dirs() 
    99         s.sort_stats(sortby) 
    100         oldout = sys.stdout 
    101         try: 
    102             sys.stdout = sio = StringIO.StringIO() 
     97        sio = StringIO.StringIO() 
     98        if sys.version_info >= (2, 5): 
     99            s = pstats.Stats(os.path.join(self.path, filename), stream=sio) 
     100            s.strip_dirs() 
     101            s.sort_stats(sortby) 
    103102            s.print_stats() 
    104         finally: 
    105             sys.stdout = oldout 
     103        else: 
     104            # pstats.Stats before Python 2.5 didn't take a 'stream' arg, 
     105            # but just printed to stdout. So re-route stdout. 
     106            s = pstats.Stats(os.path.join(self.path, filename)) 
     107            s.strip_dirs() 
     108            s.sort_stats(sortby) 
     109            oldout = sys.stdout 
     110            try: 
     111                sys.stdout = sio 
     112                s.print_stats() 
     113            finally: 
     114                sys.stdout = oldout 
    106115        response = sio.getvalue() 
    107116        sio.close() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets