def _safeio(self, callback):
        if self.closed:
            raise ValueError("I/O operation on closed file")
        for i in range(self.retries):
            try:
                if not self.stream:
                    self.stream = self._reconnect()
                return callback(self.stream)
            except (EOFError, IOError, OSError, socket.error):
                if i >= self.retries - 1:
                    raise
                if self.stream:
                    self.stream.close()
                self.stream = None
                time.sleep(0.5)
dataset/ETHPy150Open tomerfiliba/rpyc/rpyc/experimental/retunnel.py/ReconnectingTunnelStream._safeio/original