5

I have a multithreaded Python application running on a Linux server. I can use PyDev's Debug Server to remotely debug into it, which seems like a very valuable debug resource. There is however a problem I'm seeing that's preventing it from being as helpful as I would like.

While my application is running on the server, I can go into Eclipse on the other box, suspend MainThread, get a nice stack trace of what it was up to at the time, then resume execution. It's great. However, when I try that on one of the child threads, the suspend button grays out but there's no stack trace and everything just keeps on running as normal. I can see in the Debug window that there IS a child thread and it's PID, but can't really control it or see what it is up to. Right-clicking and trying the helpful-sounding "copy stack" only gives me "Thread-4 - pid29848_seq5".

Breakpoints seem to work okay. If a child thread hits one of those, I can step through and watch variables and such. However, using that effectively requires me to already have a specific point of interest in the code. I'm really more looking to run my application and, when it gets into an unusual state, use PyDev to see what's up.

Do I have something wrong with my setup? Is this just a limitation of PyDev I'm up against? How can I see what's going on with the child threads?

R.Dowdy
  • 51
  • 1
  • 3
  • I'm having the same problem. Eclipse, PyDev, Django, remote server using the manage.py runserver --noautoreload command. No luck, I can't set a breakpoint in any of the views. – Kevin Parker Nov 13 '13 at 05:57
  • So I added time.sleep(10000) into one of the get view methods of my python code, and PyDev has no stack visible, I can see the thread but there is no stack. – Kevin Parker Nov 13 '13 at 06:12
  • So I've gotten to the point where I've been able to see the stack inside of threads by adding: pydevd.settrace(suspend=False) just before the breakpoint, anywhere in the thread before the code with a breakpoint will do, but not sure why this is needed because according to python's own docs for settrace() "Set a trace function for all threads started from the threading module.". Will be looking into this further. – Kevin Parker Nov 13 '13 at 07:29
  • Possible duplicate of [Can I put break points on background threads in Python?](http://stackoverflow.com/questions/3114719/can-i-put-break-points-on-background-threads-in-python) – studgeek May 06 '16 at 00:00

3 Answers3

0

I managed to figure it after looking at one of Fabio's posts:

threading.settrace(pydevd.GetGlobalDebugger().trace_dispatch)

Should be added after you call pydev.settrace()

Kevin Parker
  • 16,975
  • 20
  • 76
  • 105
0

I was able to setup remote debugger and set breakpoints in threaded application in eclipse with pydev: http://devlvl99.blogspot.com/2014/01/debug-python-thread-multithreaded-pydev.html

-2

Given that Python doesn't really do threads properly (the GIL is bound to cock things up one way or another) I wouldn't be surprised if debugging them was a less than thrilling experience. If it comes to that it's not that good an experience either debugging C/C++ threads, even under the latest versions of GDB and CDT.

I don't actually know for sure but I've a hunch that adopting multiple processes in Python instead of multiple threads might make your experience better. If you arrange things so that a single instance of Eclipse/PyDev was debugging a single Python process you might end up with a lot of windows on your screen but it will be a much more flexible debugging experience.

Thats what I used to do under VxWorks in C, where there was no threads or processes just tasks. A consequence was that you could run a debugger for each task and it was wonderful.

bazza
  • 7,580
  • 15
  • 22