def manage_fans(self):
        FAN_LEV1_UP_TEMP = 57700  # temperature
        FAN_LEV1_DOWN_TEMP = 0  # unused
        FAN_LEV1_SPEED_PERC = DUTY_MAX  # percentage*/

        FAN_LEV2_UP_TEMP = 53000
        FAN_LEV2_DOWN_TEMP = 52700
        FAN_LEV2_SPEED_PERC = 80

        FAN_LEV3_UP_TEMP = 49500
        FAN_LEV3_DOWN_TEMP = 47700
        FAN_LEV3_SPEED_PERC = 65

        FAN_LEV4_UP_TEMP = 0  # unused
        FAN_LEV4_DOWN_TEMP = 42700
        FAN_LEV4_SPEED_PERC = 40

        thermal = ThermalUtil()
        fan = FanUtil()

        temp2 = thermal.get_thermal_2_val()
        if temp2 is None:
            return False

        temp3 = thermal.get_thermal_3_val()
        if temp3 is None:
            return False

        new_temp = (temp2 + temp3) / 2

        for x in range(fan.get_idx_fan_start(), fan.get_num_fans() + 1):
            fan_stat = fan.get_fan_status(x)
            if fan_stat is None:
                return False
            if fan_stat is False:
                self._new_perc = FAN_LEV1_SPEED_PERC
                logging.debug(
                    'INFO. SET new_perc to %d (FAN fault. fan_num:%d)',
                    self._new_perc, x)
                break
            logging.debug('INFO. fan_stat is True (fan_num:%d)', x)

        if fan_stat is not None and fan_stat is not False:
            diff = new_temp - self._ori_temp
            if diff == 0:
                logging.debug(
                    'INFO. RETURN. THERMAL temp not changed. %d / %d (new_temp / ori_temp)',
                    new_temp, self._ori_temp)
                return True
            else:
                if diff >= 0:
                    is_up = True
                    logging.debug(
                        'INFO. THERMAL temp UP %d / %d (new_temp / ori_temp)',
                        new_temp, self._ori_temp)
                else:
                    is_up = False
                    logging.debug(
                        'INFO. THERMAL temp DOWN %d / %d (new_temp / ori_temp)',
                        new_temp, self._ori_temp)

            if is_up is True:
                if new_temp >= FAN_LEV1_UP_TEMP:
                    self._new_perc = FAN_LEV1_SPEED_PERC
                elif new_temp >= FAN_LEV2_UP_TEMP:
                    self._new_perc = FAN_LEV2_SPEED_PERC
                elif new_temp >= FAN_LEV3_UP_TEMP:
                    self._new_perc = FAN_LEV3_SPEED_PERC
                else:
                    self._new_perc = FAN_LEV4_SPEED_PERC
                logging.debug(
                    'INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)',
                    self._new_perc, new_temp)
            else:
                if new_temp <= FAN_LEV4_DOWN_TEMP:
                    self._new_perc = FAN_LEV4_SPEED_PERC
                elif new_temp <= FAN_LEV3_DOWN_TEMP:
                    self._new_perc = FAN_LEV3_SPEED_PERC
                elif new_temp <= FAN_LEV2_DOWN_TEMP:
                    self._new_perc = FAN_LEV2_SPEED_PERC
                else:
                    self._new_perc = FAN_LEV1_SPEED_PERC
                logging.debug(
                    'INFO. SET. FAN_SPEED as %d (new THERMAL temp:%d)',
                    self._new_perc, new_temp)

        cur_perc = fan.get_fan_duty_cycle()
        if cur_perc == self._new_perc:
            logging.debug(
                'INFO. RETURN. FAN speed not changed. %d / %d (new_perc / ori_perc)',
                self._new_perc, cur_perc)
            return True

        set_stat = fan.set_fan_duty_cycle(self._new_perc)
        if set_stat is True:
            logging.debug('INFO: PASS. set_fan_duty_cycle (%d)',
                          self._new_perc)
        else:
            logging.debug('INFO: FAIL. set_fan_duty_cycle (%d)',
                          self._new_perc)

        logging.debug('INFO: GET. ori_perc is %d. ori_temp is %d', cur_perc,
                      self._ori_temp)
        self._ori_temp = new_temp
        logging.debug('INFO: UPDATE. ori_perc to %d. ori_temp to %d', cur_perc,
                      self._ori_temp)

        return True
def handler(signum, frame):
    fan = FanUtil()
    logging.debug('INFO:Cause signal %d, set fan speed max.', signum)
    fan.set_fan_duty_cycle(DUTY_MAX)
    sys.exit(0)