Skip to content

Commit

Permalink
hw-mgmt: thermal: Fix issue "RuntimeError: reentrant call inside"
Browse files Browse the repository at this point in the history
Fix issue:  Logging Error in TC Log writing dmesg: RuntimeError: reentrant call inside

Bug: 3630148

Signed-off-by: Oleksandr Shamray <[email protected]>
  • Loading branch information
sholeksandr committed Oct 19, 2023
1 parent 0639cd5 commit edeb172
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion usr/usr/bin/hw_management_thermal_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def __init__(self, use_syslog=False, log_file=None, verbosity=20):
self.logger.setLevel(logging.DEBUG)
self.logger.propagate = False
self.logger_fh = None
self.logger_emit = True

self.set_param(use_syslog, log_file, verbosity)

Expand Down Expand Up @@ -535,6 +536,13 @@ def stop(self):
for handler in handler_list:
handler.close()
self.logger.removeHandler(handler)
self.logger_emit = False

def close_tc_log_handler(self):
if self.logger_fh:
self.logger_fh.flush()
self.logger_fh.close()
self.logger.removeHandler(self.logger_fh)

def set_loglevel(self, verbosity):
"""
Expand All @@ -551,6 +559,10 @@ def debug(self, msg="", syslog=0):
Log "debug" message.
@param msg: message to save to log
"""
if not self.logger_emit:
return
self.logger_emit = False

msg_prefix = ""
if syslog:
msg_prefix = "@syslog "
Expand All @@ -559,13 +571,18 @@ def debug(self, msg="", syslog=0):
self.logger.debug(msg_prefix + msg)
except:
pass
self.logger_emit = True

def info(self, msg="", syslog=0):
"""
@summary:
Log "info" message.
@param msg: message to save to log
"""
if not self.logger_emit:
return
self.logger_emit = False

msg_prefix = ""
if syslog:
msg_prefix = "@syslog "
Expand All @@ -574,13 +591,18 @@ def info(self, msg="", syslog=0):
self.logger.info(msg_prefix + msg)
except:
pass
self.logger_emit = True

def notice(self, msg="", syslog=0):
"""
@summary:
Log "notice" message.
@param msg: message to save to log
"""
if not self.logger_emit:
return
self.logger_emit = False

msg_prefix = ""
if syslog:
msg_prefix = "@syslog "
Expand All @@ -589,13 +611,18 @@ def notice(self, msg="", syslog=0):
self.logger.log(logging.INFO + 5, msg_prefix + msg)
except:
pass
self.logger_emit = True

def warn(self, msg="", syslog=0):
"""
@summary:
Log "warn" message.
@param msg: message to save to log
"""
if not self.logger_emit:
return
self.logger_emit = False

msg_prefix = ""
if syslog:
msg_prefix = "@syslog "
Expand All @@ -604,13 +631,18 @@ def warn(self, msg="", syslog=0):
self.logger.warning(msg_prefix + msg)
except:
pass
self.logger_emit = True

def error(self, msg="", syslog=0):
"""
@summary:
Log "error" message.
@param msg: message to save to log
"""
if not self.logger_emit:
return
self.logger_emit = False

msg_prefix = ""
if syslog:
msg_prefix = "@syslog "
Expand All @@ -619,6 +651,7 @@ def error(self, msg="", syslog=0):
self.logger.error(msg_prefix + msg)
except:
pass
self.logger_emit = True


class RepeatedTimer(object):
Expand Down Expand Up @@ -2591,12 +2624,13 @@ def sig_handler(self, sig, *_):
"""
if sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP]:
self.exit_flag = True
self.log.close_tc_log_handler()
if self.sys_config.get("platform_support", 1):
self.stop(reason="SIG {}".format(sig))

self.log.notice("Thermal control stopped", 1)
self.log.logger_emit = False
self.log.stop()
time.sleep(200 / 1000)
os._exit(0)

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -2843,6 +2877,7 @@ def stop(self, reason=""):
self.log.notice("Thermal control state changed {} -> {} reason:{}".format(self.state, CONST.STOPPED, reason), 1)
self.state = CONST.STOPPED
self._set_pwm(CONST.PWM_MAX, reason="TC stop")
self.log.notice("Set FAN PWM {}".format(self.pwm_target), 1)

# ----------------------------------------------------------------------
def run(self):
Expand Down

0 comments on commit edeb172

Please sign in to comment.