[python] How to tell if a connection is dead in python