Created
August 25, 2014 03:18
-
-
Save tianweidut/befd2fcb4b3ee48e89a7 to your computer and use it in GitHub Desktop.
pdb in subprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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