Mysql While Loop Exit Python Script