<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cmdloop(self):
 """Start the main loop of the interactive shell. The preloop() and postloop() methods are always run before and after the main loop, respectively. Returns: 'root': Inform the parent shell to to keep exiting until the root shell is reached. 'all': Exit all the way back the the command line shell. False, None, or anything that are evaluated as False: Exit this shell, enter the parent shell. An integer: The depth of the shell to exit to. 0 = root shell. History: _ShellBase histories are persistently saved to files, whose name matches the prompt string. For example, if the prompt of a subshell is '(Foo-Bar-Kar)$ ', the name of its history file is s-Foo-Bar-Kar. The history_fname property encodes this algorithm. All history files are saved to the the directory whose path is self._temp_dir. Subshells use the same temp_dir as their parent shells, thus their root shell. The history of the parent shell is saved and restored by the parent shell, as in launch_subshell(). The history of the subshell is saved and restored by the subshell, as in cmdloop(). When a subshell is started, i.e., when the cmdloop() method of the subshell is called, the subshell will try to load its own history file, whose file name is determined by the naming convention introduced earlier. Completer Delimiters: Certain characters such as '-' could be part of a command. But by default they are considered the delimiters by the readline library, which causes completion candidates with those characters to malfunction. The old completer delimiters are saved before the loop and restored after the loop ends. This is to keep the environment clean. """

        self.print_debug("Enter subshell '{}'".format(self.prompt))

        # Save the completer function, the history buffer, and the
        # completer_delims.
        old_completer = readline.get_completer()
        old_delims = readline.get_completer_delims()
        new_delims = ''.join(list(set(old_delims) - set(_ShellBase._non_delims)))
        readline.set_completer_delims(new_delims)

        # Load the new completer function and start a new history buffer.
        readline.set_completer(self.__driver_stub)
        readline.clear_history()
        if os.path.isfile(self.history_fname):
            readline.read_history_file(self.history_fname)

        # main loop
        try:
            # The exit_directive:
            #       True        Leave this shell, enter the parent shell.
            #       False       Continue with the loop.
            #       'root'      Exit to the root shell.
            #       'all'       Exit to the command line.
            #       an integer  The depth of the shell to exit to. 0 = root
            #                   shell. Negative number is taken as error.
            self.preloop()
            while True:
                exit_directive = False
                try:
                    if self.batch_mode:
                        line = self._pipe_end.recv()
                    else:
                        line = input(self.prompt).strip()
                except EOFError:
                    line = _ShellBase.EOF

                try:
                    exit_directive = self.__exec_line__(line)
                except:
                    self.stderr.write(traceback.format_exc())

                if type(exit_directive) is int:
                    if len(self._mode_stack) > exit_directive:
                        break
                    if len(self._mode_stack) == exit_directive:
                        continue
                if self._mode_stack and exit_directive == 'root':
                    break
                if exit_directive in { 'all', True, }:
                    break
        finally:
            self.postloop()
            # Restore the completer function, save the history, and restore old
            # delims.
            readline.set_completer(old_completer)
            readline.write_history_file(self.history_fname)
            readline.set_completer_delims(old_delims)

        self.print_debug("Leave subshell '{}': {}".format(self.prompt, exit_directive))

        return exit_directive