Mastering 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.
0:04 Maybe something weird is going on right around the time
0:08 when o is greater than and 500, or something.
0:12 So we could start out by putting a breakpoint here and say
0:16 okay what's going to happen at this particular side,
0:21 okay so o is 1, great, so we keep going, o is 3
0:25 and we can even do this version to just keep running to the next breakpoint,
0:28 13, 21, okay, 233, 987 right,
0:33 now maybe that's where something is happening
0:35 we want to stop now and look at it and see how it's evaluated
0:39 this is super common when you have lots of loops
0:41 or you maybe have some accounts and you're working with your web app
0:47 and you want to see what when we get to this particular account,
0:49 or this record that is an entry in our stores catalog or something like that
0:55 and you want to stop on that one, that's the problematic one.
0:57 So there's a couple of things we can do
1:00 we can come down here, first of all we can add special watches right
1:04 we can say well I'm interested when o is greater than 500,
1:09 it's true, so let's start over and is it greater than 500? no
1:16 run, run, run, right, obviously this is easy for you looking
1:21 but there could be much more complicated things you're testing
1:24 this thing equals that, this set is contained in that set right
1:27 so you could do that sort of testing.
1:29 Now this is switched to true, great
1:31 so this sort of ability to watch these expressions and not just variables is cool
1:35 but we can do better, so let's come over here and say right click
1:39 and notice all the stuff we get whether this is enabled
1:41 whether it should suspend just this thread or all the threads,
1:45 what is the condition here, let's say o,
1:49 notice, intellisense, autocomplete right here, so fantastic
1:55 500, we could even get more
1:58 if we click this we could even have it log a message
2:02 let's say log a message here, something like that,
2:05 we could say stop, there's all sorts of features we can do here
2:08 so now if we just restart or debug, wait for a second,
2:13 bam, it stops exactly when the first time o is greater than 500
2:18 it will save you a ton of time
2:21 and by the way, it even logged that breakpoint reached
2:25 we could even put out a little better message or something
2:27 but click right here it takes you right back,
2:29 not super interesting because we were there
2:32 but far away, click here takes you right back.
2:34 Notice the icon right here, there's a little question mark
2:37 because this isn't always a breakpoint it's a conditional breakpoint.
2:41 So these conditional breakpoints I don't find I use them that often
2:45 but when I do, they're really helpful
2:47 because you're not juggling around all these different scenarios
2:50 you just put it into the breakpoint,
2:52 let it run and it stops right when it should, it's great.