Effective PyCharm Transcripts
Chapter: Debugging Python applications
Lecture: Conditional breakpoints

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Now let's come back and look at a slightly different scenario. Maybe something weird is going on right around the time
0:09 when o is greater than and 500, or something. So we could start out by putting a breakpoint here and say
0:17 okay what's going to happen at this particular side, okay so o is 1, great, so we keep going, o is 3
0:26 and we can even do this version to just keep running to the next breakpoint, 13, 21, okay, 233, 987 right,
0:34 now maybe that's where something is happening we want to stop now and look at it and see how it's evaluated
0:40 this is super common when you have lots of loops or you maybe have some accounts and you're working with your web app
0:48 and you want to see what when we get to this particular account, or this record that is an entry in our stores catalog or something like that
0:56 and you want to stop on that one, that's the problematic one. So there's a couple of things we can do
1:01 we can come down here, first of all we can add special watches right we can say well I'm interested when o is greater than 500,
1:10 it's true, so let's start over and is it greater than 500? no run, run, run, right, obviously this is easy for you looking
1:22 but there could be much more complicated things you're testing this thing equals that, this set is contained in that set right
1:28 so you could do that sort of testing. Now this is switched to true, great
1:32 so this sort of ability to watch these expressions and not just variables is cool but we can do better, so let's come over here and say right click
1:40 and notice all the stuff we get whether this is enabled whether it should suspend just this thread or all the threads,
1:46 what is the condition here, let's say o, notice, intellisense, autocomplete right here, so fantastic 500, we could even get more
1:59 if we click this we could even have it log a message let's say log a message here, something like that,
2:06 we could say stop, there's all sorts of features we can do here so now if we just restart or debug, wait for a second,
2:14 bam, it stops exactly when the first time o is greater than 500 it will save you a ton of time and by the way, it even logged that breakpoint reached
2:26 we could even put out a little better message or something but click right here it takes you right back, not super interesting because we were there
2:33 but far away, click here takes you right back. Notice the icon right here, there's a little question mark
2:38 because this isn't always a breakpoint it's a conditional breakpoint. So these conditional breakpoints I don't find I use them that often
2:46 but when I do, they're really helpful because you're not juggling around all these different scenarios you just put it into the breakpoint,
2:53 let it run and it stops right when it should, it's great.


Talk Python's Mastodon Michael Kennedy's Mastodon