Search code examples
pythonvscode-debugger

when debuging python file in vscode, launch program seems to run the full file before pause in the first breakpoint


enter image description here print line is behine the first breakpoint, but the result is already in terminal

I tryed to look https://code.visualstudio.com/docs/python/debugging but not find any similar args.

edit:

I realize that the problem will only occur when I name the file django.py.

When I rename the file to other name like website.py, it won't occur.

I wander if there are other names that will trigger this bug.

below are my launch.json

{
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
        }
    ]
}

Solution

  • This is because django.py conflicts with other files.

    An extract from the documentation

    You’ll need to avoid naming projects after built-in Python or Django components. In particular, this means you should avoid using names like django (which will conflict with Django itself) or test (which conflicts with a built-in Python package).


    I.e. some other process(es) is looking for, and running django.py. And your file is over-writing the other file.

    To fix your issue, just avoid naming the file django.py or test.py