How do I attach a remote debugger to a Python process?

后端 未结 5 1203
慢半拍i
慢半拍i 2020-12-02 05:28

I\'m tired of inserting

import pdb; pdb.set_trace()

lines into my Python programs and debugging through the console. How do I connect a rem

5条回答
  •  不知归路
    2020-12-02 05:51

    A little bit late, but here is a very lightweight remote debugging solution courtesy of http://michaeldehaan.net/post/35403909347/tips-on-using-debuggers-with-ansible:

    1. pip install epdb on the remote host.
    2. Make sure your firewalling setup is not allowing non-local connections to port 8080 on the remote host, since epdb defaults to listening on any address (INADDR_ANY), not 127.0.0.1.
    3. Instead of using import pdb; pdb.set_trace() in your program, use import epdb; epdb.serve().
    4. Securely log in to the remote host, since epdb.connect() uses telnet.
    5. Attach to the program using python -c 'import epdb; epdb.connect()'.

    Adjust the security bits to suit your local network setup and security stance, of course.

提交回复
热议问题