def get_joystick(): while True: try: joystick = Joystick() break except Exception: print('Error happened while recognizing the joystick. Retrying in 1 second...') Joystick.reinit() sleep(1) return joystick