From ead67de883de0429934fc9edbd3019148b0b088a Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 21 Sep 2017 03:20:32 +0530 Subject: [PATCH] core: make Side.write() return None rather than crash if side already closed. --- mitogen/core.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mitogen/core.py b/mitogen/core.py index a6ffc182..f67554c1 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -483,6 +483,9 @@ class Side(object): return s def write(self, s): + if self.fd is None: + return None + written, disconnected = io_op(os.write, self.fd, s[:CHUNK_SIZE]) if disconnected: return None @@ -613,7 +616,7 @@ class Stream(BasicStream): written = self.transmit_side.write(self._output_buf) if written is None: LOG.debug('%r.on_transmit(): disconnection detected', self) - self.on_disconnect() + self.on_disconnect(broker) return IOLOG.debug('%r.on_transmit() -> len %d', self, written)