modified python script to account for if mysql connection closes