diff options
| author | Gustavo Picon <tabo@tabo.pe> | 2015-12-02 15:33:19 -0800 |
|---|---|---|
| committer | Gustavo Picon <tabo@tabo.pe> | 2015-12-02 15:33:19 -0800 |
| commit | f816c812eda58a0f6548cb965fe5de9b33ed47ec (patch) | |
| tree | 2a2345b281ca9e841d3b8ab78596a8b39cd08f5b /cherrypy/lib | |
| parent | 1265757ea8385fc365af57dea26583b47507efdf (diff) | |
| download | cherrypy-git-3.8.1.tar.gz | |
#1333 Make cpstats python3.3+ compatible3.8.1
Diffstat (limited to 'cherrypy/lib')
| -rw-r--r-- | cherrypy/lib/cpstats.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/cherrypy/lib/cpstats.py b/cherrypy/lib/cpstats.py index a8661a14..4aeabd7d 100644 --- a/cherrypy/lib/cpstats.py +++ b/cherrypy/lib/cpstats.py @@ -210,6 +210,7 @@ def extrapolate_statistics(scope): # -------------------- CherryPy Applications Statistics --------------------- # +import sys import threading import time @@ -294,6 +295,11 @@ class ByteCountWrapper(object): average_uriset_time = lambda s: s['Count'] and (s['Sum'] / s['Count']) or 0 +def _get_threading_ident(): + if sys.version_info >= (3, 3): + return threading.get_ident() + return threading._get_ident() + class StatsTool(cherrypy.Tool): """Record various information about the current request.""" @@ -322,7 +328,7 @@ class StatsTool(cherrypy.Tool): appstats['Current Requests'] += 1 appstats['Total Requests'] += 1 - appstats['Requests'][threading._get_ident()] = { + appstats['Requests'][_get_threading_ident()] = { 'Bytes Read': None, 'Bytes Written': None, # Use a lambda so the ip gets updated by tools.proxy later @@ -339,7 +345,7 @@ class StatsTool(cherrypy.Tool): debug=False, **kwargs): """Record the end of a request.""" resp = cherrypy.serving.response - w = appstats['Requests'][threading._get_ident()] + w = appstats['Requests'][_get_threading_ident()] r = cherrypy.request.rfile.bytes_read w['Bytes Read'] = r @@ -605,7 +611,13 @@ table.stats2 th { """Return ([headers], [rows]) for the given collection.""" # E.g., the 'Requests' dict. headers = [] - for record in v.itervalues(): + try: + # python2 + vals = v.itervalues() + except AttributeError: + # python3 + vals = v.values() + for record in vals: for k3 in record: format = formatting.get(k3, missing) if format is None: |
