I\'m trying to debug a deadlock in a multi-threaded Python application after it has locked up. Is there a way to attach a debugger to inspect the state of the process?
This can be used as a dead simple "remote" debugger:
import sys
import socket
import pdb
def remote_trace():
server = socket.socket()
server.bind(('0.0.0.0', 12345))
server.listen()
client, _= server.accept()
stream = client.makefile('rw')
sys.stdin = sys.stdout = sys.stderr = stream
pdb.set_trace()
remote_trace()
# Execute in the shell: `telnet 127.0.0.1 12345`
On Windows it's easier to use Netcat instead of Telnet (which will also work on linux).