def send(self, body): if isinstance(body, str): body = body.encode() try: self.writer.write(body) self.writer.write(b'\n') except BrokenPipeError: raise ConnectionClosed()