ofir1080
ofir1080

Reputation: 145

Debugging python code in subprocess using Breakpoints in VScode

I have been trying to debug a massive PyTorch model in VScode.
The starting point of the code first processes a configuration file, and then runs a subprocess containing the cofigs.
The issue is that after calling subprocess.call functions, the VScode, the code is executed in an external sub-process, which does not allow to use breakpoint. example code:

def main():
    args = parse_args()
    cmd = construct_cmd(args)
    subprocess.call(cmd, shell=True)

where cmd is the string command to be executed, but after this line, all breakpoints are ignored (probably because a sub-process runs this command. Any solutions how to solve this?

Upvotes: 4

Views: 970

Answers (1)

S.H.W
S.H.W

Reputation: 121

I had the same problem. After spending many hours and trying different things, like changing launch.json file and using different IDEs and pdb package, I accidentally found that removing shell=True solves the problem! I don't know the reason but it works (it would be great if someone tells the reason). So it's enough to use the following code:

def main():
    args = parse_args()
    cmd = construct_cmd(args)
    subprocess.call(cmd)

Upvotes: 0

Related Questions