6

I'd like to be able to debug Punjab, a twisted python application, in Netbeans so that I can step through the code. How can I do that? Alternatively, how could I do it in a different debugger?

leeb
  • 699
  • 7
  • 14

1 Answers1

11

Since you're trying to debug a twisted application, you have a few options:

  1. If you're running via twistd you can use the -b command-line options:

       -b, --debug            run the application in the Python Debugger (implies
                              nodaemon), sending SIGUSR2 will drop into debugger
    
  2. You can run manhole in your twisted process - this allows you to telnet into the server and examine Python objects - http://twistedmatrix.com/documents/current/core/howto/telnet.html

  3. You can optionally run pdb manually - see: http://docs.python.org/library/pdb.html

rlotun
  • 7,897
  • 4
  • 28
  • 23
  • I'm just starting to use `twisted` and thanks for tips on how to debug twisted. With twisted event loop and stuff its hard to debug in the conventional way and I'm hoping there are more answers to this question. – Jeffrey Jose Mar 29 '10 at 18:23
  • No problem. In fact, if you find any other different methods please let me know! – rlotun Mar 29 '10 at 19:58
  • Thanks for the response. I too am hoping there is a way to use a graphical debugger, but shall mark this as the best available answer. – leeb Apr 12 '10 at 21:49
  • 1
    I should also mention that I recently found out the Wing IDE has Twisted debugging support (see http://www.wingware.com/doc/howtos/twisted) – rlotun Apr 13 '10 at 06:18
  • This --debug option causes twistd to drop into pdb on every raised exception. How do we stop this behavior? I just want to stop at certain points. – Chris Jun 06 '18 at 21:10
  • 1
    I found out how to disable the pdb break on every single exception: `from twisted.python import failure; failure.DO_POST_MORTEM=False` --debug ends up resetting the original stdout/stderr that gets rerouted when twistd runs. If you don't specify --debug or rewire stdout/stderr back yourself, then any other pdb breakpoint you set in your code won't show up. – Chris Jun 08 '18 at 17:13