Silencing broken pipe errors (`[Errno 32] Broken pipe`) in python with WSGI+Pyramid -
i have rather simple, naive python/wsgi/pyramid web-server.
it's run using wsgiref.simple_server.make_server()
, on server built using pyramid.config.configurator().make_wsgi_app()
. server works fine.
however, application it's serving has lot of javascript image mouseover popups. if run mouse across page, can generate 20+ image requests. fine (it's internal thing, not lot of users).
however, doing causes server emit half dozen error tracebacks:
10.1.1.4 - - [25/apr/2014 01:56:42] "get /*snip* 500 59 ---------------------------------------- exception happened during processing of request ('10.1.1.4', 18338) traceback (most recent call last): file "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run self.finish_response() file "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response self.write(data) file "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write self.send_headers() file "/usr/lib/python3.4/wsgiref/handlers.py", line 333, in send_headers self._write(bytes(self.headers)) file "/usr/lib/python3.4/wsgiref/handlers.py", line 453, in _write self.stdout.write(data) file "/usr/lib/python3.4/socket.py", line 391, in write return self._sock.send(b) brokenpipeerror: [errno 32] broken pipe during handling of above exception, exception occurred: traceback (most recent call last): file "/usr/lib/python3.4/wsgiref/handlers.py", line 141, in run self.handle_error() file "/usr/lib/python3.4/wsgiref/handlers.py", line 368, in handle_error self.finish_response() file "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response self.write(data) file "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write self.send_headers() file "/usr/lib/python3.4/wsgiref/handlers.py", line 331, in send_headers if not self.origin_server or self.client_is_modern(): file "/usr/lib/python3.4/wsgiref/handlers.py", line 344, in client_is_modern return self.environ['server_protocol'].upper() != 'http/0.9' typeerror: 'nonetype' object not subscriptable during handling of above exception, exception occurred: traceback (most recent call last): file "/usr/lib/python3.4/socketserver.py", line 306, in _handle_request_noblock self.process_request(request, client_address) file "/usr/lib/python3.4/socketserver.py", line 332, in process_request self.finish_request(request, client_address) file "/usr/lib/python3.4/socketserver.py", line 345, in finish_request self.requesthandlerclass(request, client_address, self) file "/usr/lib/python3.4/socketserver.py", line 666, in __init__ self.handle() file "/usr/lib/python3.4/wsgiref/simple_server.py", line 126, in handle handler.run(self.server.get_app()) file "/usr/lib/python3.4/wsgiref/handlers.py", line 144, in run self.close() file "/usr/lib/python3.4/wsgiref/simple_server.py", line 35, in close self.status.split(' ',1)[0], self.bytes_sent attributeerror: 'nonetype' object has no attribute 'split'
i understand why i'm getting broken pipe errors (the request image canceled before image has transfered, because mouseover popup has closed), , seems harmless.
however, have no idea how silence traceback. there thousands of them in logs, , makes debugging actual errors nightmare. don't care i'm getting broken pipe errors, how can catch them , swallow them silently?
it seems wsgiref.simple_server.make_server()
installs internal handler catches brokenpipeerror: [errno 32] broken pipe
, prints traceback, , swallows error. i've tried wrapping run_server()
call in try-except clause, , doesn't have effect.
i wound switching using cherrypy wsgi server. doesn't suffer broken pipe log issues, , far more robust well.
it uses threadpool, it's more performant (multiple requests aren't blocking!).
Comments
Post a Comment