correctly handle KeyboardInterrupt