0

I want to add an interactive console to debug a running python progam. I want to be able to "call" custom commands (but not external system programs) and interact with instances and statuses of my program.

I basically need an "SSH server" built into my python program.

I could write a TCP server, a parser and everything else all I need, but since I will be in a shell I would also like other things like "autocompletion" and "history", and, why not, authentication... Things that would involve some more advanced vt100 commands like bold/highlights, write and delete lines and chars.

Is there anything already done?

1 Answers1

0

You can check if the code module from the standard lib helps you here. It provides the InteractiveConsole and InteractiveInterpreter classes, as well as some convenience function.

A very simple example:

import code

def foo():
    bar = 1
    for i in range(3):
        print(bar*i)

code.interact(local=locals())
foo()

When running code, an interactive shell will open, you can find foo in dir(), run it and so forth.

srn
  • 614
  • 3
  • 15