Last active
March 27, 2019 14:11
-
-
Save jaraco/a7508147a72aa23e0936adbdc1395743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: future_fstrings | |
__requires__ = [ | |
'cherrypy!=18.1.0', | |
'future-fstrings', | |
'backports.functools_lru_cache; python_version=="2.7"', | |
] | |
import logging | |
try: | |
from functools import lru_cache | |
except ImportError: | |
from backports.functools_lru_cache import lru_cache | |
import cherrypy.lib.cpstats | |
class CherootStatistics(cherrypy.process.plugins.SimplePlugin): | |
def main(self): | |
self._main(self.bus.log) | |
@staticmethod | |
@lru_cache() | |
def _main(log): | |
keys = ( | |
key | |
for key in logging.statistics.keys() | |
if key.startswith('Cheroot HTTPServer') | |
) | |
for key in keys: | |
log(f'Enabling {key} statistics') | |
logging.statistics[key]['Enabled'] = True | |
class Server: | |
@cherrypy.expose | |
def index(self): | |
return 'Hello World' | |
cpstats = cherrypy.lib.cpstats.StatsPage() | |
def main(): | |
CherootStatistics(cherrypy.engine).subscribe() | |
config = { | |
'global': { | |
'server.socket_host': '::0', | |
}, | |
} | |
cherrypy.quickstart(Server(), config=config) | |
__name__ == '__main__' and main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment