diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index 4437581dca1..270f4cd69d9 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -561,7 +561,8 @@ class StreamRequestHandler(BaseRequestHandler): self.wfile = self.connection.makefile('wb', self.wbufsize) def finish(self): - self.wfile.flush() + if not self.wfile.closed: + self.wfile.flush() self.wfile.close() self.rfile.close()