Handle KeyboardInterrupt correctly