How to connect remote debugger to Python process?

I'm tired of sticking

import pdb; pdb.set_trace() 

into my Python programs and debugging through the console. How to connect a remote debugger and insert breakpoints from a civilized user interface?

+51
python remote-debugging
Feb 12 '09 at 20:54
source share
4 answers

use winpdb . It is a platform-independent Python GPL graphic debugger with support for remote debugging over the network, multiple threads, namespace changes, built-in debugging, encrypted communications, and up to 20 times faster than pdb.

Features:

  • GPL license. Winpdb is free software.
  • Compatible with CPython 2.3 through 2.6 and Python 3000
  • WxPython 2.6 compatible - 2.8
  • Independent platform and tested on Ubuntu Gutsy and Windows XP.
  • User Interfaces: rpdb2 is console based, and winpdb requires wxPython 2.6 or later.

Screenshot http://winpdb.org/images/screenshot_winpdb_small.jpg

+57
Feb 13 '09 at 5:32
source share

Well, you can get something very similar to that using a twisted hatch that works as follows:

 from twisted.internet import reactor from twisted.cred import portal, checkers from twisted.conch import manhole, manhole_ssh def getManholeFactory(namespace): realm = manhole_ssh.TerminalRealm() def getManhole(_): return manhole.Manhole(namespace) realm.chainedProtocolFactory.protocolFactory = getManhole p = portal.Portal(realm) p.registerChecker( checkers.InMemoryUsernamePassword DatabaseDontUse(admin='foobar')) f = manhole_ssh.ConchFactory(p) return f reactor.listenTCP(2222, getManholeFactory(globals())) reactor.run() 

Then you just go into the program via ssh;

 $ ssh admin@localhost -p 2222 admin@localhost password: 

Using foobar as a password.

When you log in, you will get a standard python hint where you can simply pop out the data. This is not quite the same as receiving a trace sent to the host.

Now it can be difficult to integrate into the GUI program, in which case you may need to choose a different reactor, for example, for gtk-based programs used by gtk2reactor, etc.

If you want the actual trace to be sent, you need to create a socket channel for stderr, stdin and stdout, which goes through the network instead of printing to your local host. It should not be too difficult to perform using twisted ones.

+17
Feb 12 '09 at 21:07
source share

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

  • pip install epdb on the remote host.
  • Make sure that the firewall setting does not allow non-local connections to port 8080 on the remote host, since epdb is used by default to listen on any address ( INADDR_ANY ), not 127.0.0.1.
  • Instead of using import pdb; pdb.set_trace() import pdb; pdb.set_trace() in your program use import epdb; epdb.serve() import epdb; epdb.serve() .
  • Secure login to a remote host since epdb.connect() uses telnet.
  • Attach to the program using python -c 'import epdb; epdb.connect()' python -c 'import epdb; epdb.connect()' .

Configure the security bits according to your LAN settings and security.

+10
Apr 04 '15 at 21:55
source share

Two solutions from modern IDEs:

  • Cross-platform PTVS Remote Debugging

  • PyCharm / PyDev Remote Debugging

+2
Mar 02 '15 at 15:37
source share



All Articles