Postgresql While Loop Exit Python Venv Deactivate