python: handle socket.timeout discretely when connecting or sending