How to attach debugger to a python subproccess?

前端 未结 8 2302
旧巷少年郎
旧巷少年郎 2020-12-22 23:49

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 alrea

8条回答
  •  长情又很酷
    2020-12-23 00:43

    remote-pdb can be used to debug sub-processes. After installation, put the following lines in the code you need to debug:

    import remote_pdb
    remote_pdb.set_trace()
    

    remote-pdb will print a port number which will accept a telnet connection for debugging that specific process. There are some caveats around worker launch order, where stdout goes when using various frontends, etc. To ensure a specific port is used (must be free and accessible to the current user), use the following instead:

    from remote_pdb import RemotePdb
    RemotePdb('127.0.0.1', 4444).set_trace()
    

    remote-pdb may also be launched via the breakpoint() command in Python 3.7.

提交回复
热议问题