Skip to content

Instantly share code, notes, and snippets.

@tianweidut
Created August 25, 2014 03:18
Show Gist options
  • Save tianweidut/befd2fcb4b3ee48e89a7 to your computer and use it in GitHub Desktop.
Save tianweidut/befd2fcb4b3ee48e89a7 to your computer and use it in GitHub Desktop.
pdb in subprocess
#ref: http://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
import sys
import pdb
class ForkedPdb(pdb.Pdb):
"""A Pdb subclass that may be used
from a forked multiprocessing child
"""
def interaction(self, *args, **kwargs):
_stdin = sys.stdin
try:
sys.stdin = file('/dev/stdin')
pdb.Pdb.interaction(self, *args, **kwargs)
finally:
sys.stdin = _stdin
#Use it the same way you might use the classic Pdb:
ForkedPdb().set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment