PyCharm out of step when debugging

Answered

Sometimes, Pycharm loses its place when stepping through code in the debugger. It is happening at the moment. The line that is highlighted in blue as the next line to be executed, is one line ahead of the actual line that will be executed next. The line number in the debugging panel is the line highlighted, not the one about to be executed. e.g. The debugging panel shows line 111, and that line is highlighted. However, the code in line 110 has not been executed yet (for testing, line 110 is: aaaa = 4, but aaaa still has value 3).

When this has happened in the past, I have been able solve it by cutting out a code segment and pasting it back in, but that hasn't worked this time. Invalidating the caches and restarting has no effect.

Has anyone else seen this? Is there anything else I can try to get PyCharm to resynchronise itself to the code.

N.B. This is not because I have edited the code while it is running. I have not.

This is on a Mac (not M1). I have updated to 2020.3.3 and the problem is still occurring.

Thanks, Julian

0
2 comments

Hi Julian,

There are two known issues when debugger highlights the wrong line:

https://youtrack.jetbrains.com/issue/PY-39432

https://youtrack.jetbrains.com/issue/PY-46533

I bet you are facing one of them.

Could you try the workaround mentioned in the second issue (PYDEVD_USE_CYTHON=NO) and let me know if it helps?

0

Thanks. Adding that environment variable seems to have solved the problem of the debugger highlighting the wrong line. However, there is one thing that is still not right. This code reproduces the problem:

i = 0
a = 1
while i < 2:
if a == 1:
a = 2
if a == 3:
b = 1
continue
else:
b = 2

When stepping through in the debugger, the 'continue' is never highlighted. The cursor goes straight from 'if a == 1' back to the while.

This is not a critical issue as lines of code that do something are still highlighted. However, it does mean that a breakpoint on the continue is never executed, which is not right.

I have added this as an issue https://youtrack.jetbrains.com/issue/PY-46780

Thanks for your help.

Julian

0

Please sign in to leave a comment.