It would probably be better to just change this to `if getattr(conn, 'sock', None):`, no?