Postgresql While Loop Exit In Python How Can You Measure