'Reset the IO watcher; retry as necessary'

def _reset_io_watcher(self):

    self._io_watcher.stop()
    retries = 0
    while True:
        try:
            self._io_watcher.set(self._io_watcher.fd, self._PIKA_TO_LIBEV_ARRAY[self.event_state])
            break
        except Exception:
            if (retries > 5):
                raise
            self._io_watcher.stop()
            retries += 1
    self._io_watcher.start()
