def my_finish(self):
    if not self.wfile.closed:
        try:
            self.wfile.flush()
        except socket.error:
            # A final socket error may have occurred here, such as
            # the local error ECONNABORTED.
            pass
        try:
            self.wfile.close()
            self.rfile.close()
        except socket.error:
            pass