I need to debug a child process spawned by multiprocessing.Process()
. The pdb
degugger seems to be unaware of forking and unable to attach to already running processes.
Are there any smarter python debuggers which can be attached to a subprocess?
This is an elaboration of Romuald's answer which restores the original stdin using its file descriptor. This keeps readline working inside the debugger. Besides, pdb special management of KeyboardInterrupt is disabled, in order it not to interfere with multiprocessing sigint handler.
If you are on a supported platform, try DTrace. Most of the BSD / Solaris / OS X family support DTrace.
Here is an intro by the author. You can use Dtrace to debug just about anything.
Here is a SO post on learning DTrace.
An idea I had was to create "dummy" classes to fake the implementation of the methods you are using from multiprocessing:
Winpdb is pretty much the definition of a smarter Python debugger. It explicitly supports going down a fork, not sure it works nicely with
multiprocessing.Process()
but it's worth a try.For a list of candidates to check for support of your use case, see the list of Python Debuggers in the wiki.
I've been searching for a simple to solution for this problem and came up with this:
Use it the same way you might use the classic Pdb:
Building upon @memplex idea, I had to modify it to get it to work with
joblib
by setting thesys.stdin
in the constructor as well as passing it directly along via joblib.