MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _cmdloop

Method _cmdloop

cmd2/cmd2.py:3688–3725  ·  view source on GitHub ↗

Repeatedly issue a prompt, accept input, parse it, and dispatch to appropriate commands. Parse an initial prefix off the received input and dispatch to action methods, passing them the remainder of the line as argument. This serves the same role as cmd.cmdloop().

(self)

Source from the content-addressed store, hash-verified

3686 self._alert_allowed = False
3687
3688 def _cmdloop(self) -> None:
3689 """Repeatedly issue a prompt, accept input, parse it, and dispatch to appropriate commands.
3690
3691 Parse an initial prefix off the received input and dispatch to action methods, passing them
3692 the remainder of the line as argument.
3693
3694 This serves the same role as cmd.cmdloop().
3695 """
3696 try:
3697 # Run startup commands
3698 stop = self.runcmds_plus_hooks(self._startup_commands)
3699 self._startup_commands.clear()
3700
3701 while not stop:
3702 # Get commands from user
3703 try:
3704 line = self._read_command_line(self.prompt)
3705 except KeyboardInterrupt:
3706 self.poutput("^C")
3707 line = ""
3708 except EOFError:
3709 line = "_eof"
3710
3711 # Run the command along with all associated pre and post hooks
3712 stop = self.onecmd_plus_hooks(line)
3713 finally:
3714 with self.sigint_protection:
3715 # Shut down the alert thread.
3716 if self._alert_thread is not None:
3717 with self._alert_condition:
3718 self._alert_shutdown = True
3719 self._alert_condition.notify_all()
3720
3721 # The thread is event-driven and stays suspended until notified.
3722 # We join with a 1 second timeout as a safety measure. If it hangs,
3723 # the daemon status allows the OS to reap it on exit.
3724 self._alert_thread.join(timeout=1.0)
3725 self._alert_thread = None
3726
3727 #############################################################
3728 # Parsers and functions for alias command and subcommands

Callers 2

cmdloopMethod · 0.95
test_async_alertFunction · 0.80

Calls 5

runcmds_plus_hooksMethod · 0.95
_read_command_lineMethod · 0.95
poutputMethod · 0.95
onecmd_plus_hooksMethod · 0.95
clearMethod · 0.45

Tested by 1

test_async_alertFunction · 0.64