Postgresql While Loop Exit In Python A Namespace