简体   繁体   中英

how to debug python-twisted ipdb

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM