If I'm understanding your case correctly, this is might be because time.sleep() freezes the user interface for the duration of the delay. So when you set your condition to false elsewhere on the view it doesn't actually update the script until sleep() is done.
Regardless, using time.sleep() is incredibly bad practice for many reasons: