Skip to content

Instantly share code, notes, and snippets.

@ionelmc
Created September 20, 2017 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionelmc/9989865957eb9377ca75a53c146bf116 to your computer and use it in GitHub Desktop.
Save ionelmc/9989865957eb9377ca75a53c146bf116 to your computer and use it in GitHub Desktop.
"""
Make sure you have a `socat readline unix-listen:/tmp/debugger` or `socat - unix-listen:/tmp/debugger` running in
a termial before using set_trace.
"""
def set_trace():
from pdb import Pdb
import os
import socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/tmp/debugger')
fd = sock.detach()
pdb = Pdb(stdin=os.fdopen(fd, 'r'), stdout=os.fdopen(fd, 'w'))
pdb.set_trace()
if __name__ == "__main__":
set_trace()
for i in range(10):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment