Postgresql While Loop Exit In Python Which Library