Search code examples
pythonpython-3.xpython-idle

How to handle multiple source-files debugging with idle3?


I know how to debug a single file, but a breakpoint on an imported file does not work so far.

test1.py

import test2

print(do_stuff)

test2.py

def do_stuff():
   str = "hello world" # <- set breakpoint here
   return str

When setting a breakpoint in test2.py and running test1.py in idle3, the program does not stop. How to handle multiple source-files debugging?


Solution

  • Your code is buggy in that it never runs the line with a breakpoint, which is within a function that is not called. I just tested in 3.5.4 and 3.7.0b1 on Windows and breakpoints in an imported file work fine.

    # a/tem.py (in path)
    a = 3
    b = 4  # breakpoint
    def c():
        d = 5  # breakpoint
        return 'c ran'
    
    # a/tem2.py
    from a.tem import c
    print(c)
    print(c())
    
    # prints
    <function c at 0x0000023921979840>
    c ran
    

    Running buggy code in a different IDE will not make it magically run.