How to debug python scripts that fork
In perl debugger I can use DB::get_fork_TTY() to开发者_如何学运维 debug both parent and child process in different terminals. Is there anything similar in python debugger? Or, is there any good way to debug fork in python?
You can emulate forked process if you will set instead of fork and its condition (pid == 0) always True. For debugging main process debugger will work.
For debugging multi-processing interaction better to use detailed logs as for me
The debugger in pyCharm does this nicely. It seems to use gdb with python support to accomplish that, however all the tutorials on how to do this with gdb by Hand which I've found so far didn't work for me. In pyCharm it just works.
One possible way to debug a fork is to use pdb on the main process and winpdb on the fork. You put a software break early in the fork process and attach the winpdb app once the break has been hit.
It might be possible to run the program under winpdb and attach another instance after the fork - I haven't tried this. You certainly can't attach two winpdb instances at the same time, I've tried and it fails. If it works, this would be preferable - pdb really sucks.
Provided Python has not been stripped of its debugging symbols and gdb (version above 7.0) is available, you can attach to the child and use pdb commands to debug it with:
pdb-clone --pid CHILD_PID
pdb-clone is at Pypi: http://pypi.python.org/pypi/pdb-clone/
But I'm still curious if there's any similar feature in python debugger. I happen to find this feature in perldb and I find it's very handy
No.
You don't need it.
No matter how handy it may appear in other environments, you just don't need it.
You don't need fork()
in Python; therefore you don't need fancy debugging to work with fork()
.
If you think you need fork()
you should either use subprocess
, multiprocessing
or C.
精彩评论