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?
After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.
Attach to process Last modified: 09 August 2022. Run | Attach to Process Ctrl+Alt+F5. PyCharm provides a way to attach the debugger to to a Python local process, while running a Python script launched either from your operating system or using the PyCharm terminal, but NOT in the debug mode.
Just right-click any line in the editor and select the Debug <filename> command from the context menu. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.
I've been searching for a simple to solution for this problem and came up with this:
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 = open('/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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With