0

Is there a way to run interactive debugger inside a twisted app?

  import ipdb;ipdb.set_trace()

this resolve in:

7-02-03T22:25:49+0100 [stderr#error] Traceback (most recent call last):
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
2017-02-03T22:25:49+0100 [stderr#error]     self.run()
2017-02-03T22:25:49+0100 [stderr#error]   File "bo/OLA_test.py", line 110, in run
2017-02-03T22:25:49+0100 [stderr#error]     self.wrapper.Run()
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/dist-packages/ola/ClientWrapper.py", line 278, in Run
2017-02-03T22:25:49+0100 [stderr#error]     self._ss.Run()
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/dist-packages/ola/ClientWrapper.py", line 197, in Run
2017-02-03T22:25:49+0100 [stderr#error]     self._CheckTimeouts(now)
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/dist-packages/ola/ClientWrapper.py", line 222, in _CheckTimeouts
2017-02-03T22:25:49+0100 [stderr#error]     event.Run()
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/dist-packages/ola/ClientWrapper.py", line 67, in Run
2017-02-03T22:25:49+0100 [stderr#error]     self._callback()
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch
2017-02-03T22:25:49+0100 [stderr#error]     return self.dispatch_line(frame)
2017-02-03T22:25:49+0100 [stderr#error]   File "/usr/lib/python2.7/bdb.py", line 68, in dispatch_line
2017-02-03T22:25:49+0100 [stderr#error]     if self.quitting: raise BdbQuit

with Twisted==16.6.0

summer
  • 213
  • 3
  • 12

1 Answers1

0

You just need to keep stdin and stdout attached to something useful. Make sure you don't daemonize and tell the logging system not to screw with stdio.

Alternatively, you can use a debugger that doesn't require stdin and stdout. For example, with pudb:

import pudb.remote
pudb.remote.set_trace()

Also, you didn't ask, but multiprocessing and Twisted are mostly incompatible. It's possible to get them to work reliably together with great, great care - but there are usually easier ways to accomplish the same thing.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • Thanks for reply, could you please explain why they are incompatible? I've used them togheter to share information between different process and the script is running since 124 days. – summer Feb 04 '17 at 09:16
  • You can find a bunch of questions on the topic by searching SO for "[twisted] [multiprocessing]". Here's one in particular: https://stackoverflow.com/questions/11272874/is-twisted-incompatible-with-multiprocessing-events-and-queues – Jean-Paul Calderone Feb 04 '17 at 13:02