code: def _interactive_loop(self, sin: IO[str], sout: IO[str]) -> None:
          
          self._sin = sin
          self._sout = sout
          tasknum = len(all_tasks(loop=self._loop))
          s = '' if tasknum == 1 else 's'
          self._sout.write(self.intro.format(tasknum=tasknum, s=s))
          try:
              while not self._closing.is_set():
                  self._sout.write(self.prompt)
                  self._sout.flush()
                  try:
                      user_input = sin.readline().strip()
                  except Exception as e:
                      msg = 'Could not read from user input due to:\n{}\n'
                      log.exception(msg)
                      self._sout.write(msg.format(repr(e)))
                      self._sout.flush()
                  else:
                      try:
                          self._command_dispatch(user_input)
                      except Exception as e:
                          msg = 'Unexpected Exception during command execution:\n{}\n'  # noqa
                          log.exception(msg)
                          self._sout.write(msg.format(repr(e)))
                          self._sout.flush()
          finally:
              self._sin = None  # type: ignore
              self._sout = None
docs: Main interactive loop of the monitor