Interactive remote debugging by redirecting sys.stdin and sys.stdout to a socket or pipe

carl.dhalluin at carl.dhalluin at
Wed Jul 25 11:30:49 CEST 2007


I want a simple way to interactively remote debug a running python
script which has no tty terminal attached to it. The scripts are
running standalone (i.e. they are automatically started and have no
terminal) and very infrequently come into error conditions which i
want to understand and debug. The idea is that I do the debugging as
shown below.

Is that a good way of solving my problem? Do I need anything special
for terminal emulation? What type of client should I use? I want
things like tab completion and syntax coloring of ipshell (or similar)
to work.

if <condition>:
    # If I come here I did something wrong. Send an event or email
that the failure has happened

def startRemoteDebugging():
    # open a TCP listen socket and start listening
    # as soon as someone connects to the socket, do authentication
check (e.g. username/pwd)
    # redirect sys.stdin and sys.stdout to the socket
    # start interactive python e.g. ipython ipshellembed()
    # put sys.stdin and sys.stdout back to what they were
    # debugging session is done

More information about the Python-list mailing list