-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging.statistics doesn't work in Python 3 #10
Comments
Here's the monkeypatching I'm currently doing to work around this problem: ####################################################################################
## Monkey patches for wsgiserver to fix statistics collection
####################################################################################
import io
import socket
import wsgiserver
class CP_BufferedReader(io.BufferedReader):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bytes_read = 0
def read(self, *args, **kwargs):
bs = super().read(*args, **kwargs)
self.bytes_read += len(bs)
return bs
def readline(self, *args, **kwargs):
bs = super().readline(*args, **kwargs)
self.bytes_read += len(bs)
return bs
class CP_BufferedWriter(wsgiserver.CP_BufferedWriter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bytes_written = 0
def write(self, b):
s = super().write(b)
self.bytes_written += s
return s
def CP_makefile_PY3(sock, mode='r', bufsize=io.DEFAULT_BUFFER_SIZE):
if 'r' in mode:
return CP_BufferedReader(socket.SocketIO(sock, mode), bufsize)
else:
return CP_BufferedWriter(socket.SocketIO(sock, mode), bufsize)
wsgiserver.CP_makefile = CP_makefile_PY3
#################################################################################### |
I also get an error when I first enable statistics, and behavior gets wonky:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just set
logging.statistics['WSGIserver whateverid']['Enabled'] = True
and it crashed, telling me BufferReader doesn't have an attributebytes_read
, which is true. It looks like the problem stems fromHTTPConnection
's use ofCP_makefile_PY3
in Python 3 which returns io.BufferedReader, andCP_makefile_PY2
in Python 2, which returns a custom thing that has abytes_read
attribute.The text was updated successfully, but these errors were encountered: