Menu

Pydev: Remote debugging and multiple threads

2010-02-10
2013-03-15
  • Diego Escalona

    Diego Escalona - 2010-02-10

    Hello all,

    I’m working with Pydev’s Remote Debugger and Eclipse and I have a problem with multi-thread Python applications. The remote debugger only traces the MainThread and the breakpoints it has, but if I try to add a breakpoint to a different thread it doesn’t stop.

    I’ve written a simple piece of code to test it:


    import threading
    import time
    import pydevd
    pydevd.settrace('10.101.1.193', suspend=False)
    class myThread(threading.Thread):
        def __init__(self):
            threading.Thread.__init__(self)
        
        def run(self):
            i = 10
            while i > 0:
                print "hello ", i
                i = i - 1
                time.sleep(2)
    my_thread = myThread()
    my_thread.start()
    for i in range(10):
        print "bye ", i
        time.sleep(5)
    

    If I put a breakpoint on the “print hello” line and another one on the “print bye” line, the debugger only stops on the “print bye” line, which belongs to the main thread.

    How could I make the debugger to trace the new thread and stop on its breakpoints?

    I have tried putting another settrace() entry just below the run definition and the debugging works fine, but that is something I would like to avoid. Is there any piece of code (from pydevd.py or any other file) I should change to achieve what I have explained?

    Thanks in advance.

    Kind regards.

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2010-02-10

    To make debug active on all threads, use the code below.

    import pydevd
    pydevd.settrace(suspend=False)
    import threading
    threading.settrace(pydevd.GetGlobalDebugger().trace_dispatch)

    another option would be having pydevd.settrace(suspend=False) called on the constructor of each new Thread.

    Cheers,

    Fabio

     
  • Diego Escalona

    Diego Escalona - 2010-02-12

    Thanks for the quick answer Fabio, it is working now.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.