black: re-format
black and isort are enabled in the openbmc-build-scripts on Python files
to have a consistent formatting. Re-run the formatter on the whole
repository.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I944f1915ece753f72a3fa654902d445a9749d0f9
diff --git a/lib/func_timer.py b/lib/func_timer.py
index 852bbf2..fc339c2 100644
--- a/lib/func_timer.py
+++ b/lib/func_timer.py
@@ -5,11 +5,12 @@
"""
import os
-import sys
import signal
+import sys
import time
-import gen_print as gp
+
import gen_misc as gm
+import gen_print as gp
import gen_valid as gv
@@ -30,9 +31,7 @@
second. "sleep 2" is a positional parm for the run_key function.
"""
- def __init__(self,
- obj_name='func_timer_class'):
-
+ def __init__(self, obj_name="func_timer_class"):
# Initialize object variables.
self.__obj_name = obj_name
self.__func = None
@@ -59,9 +58,11 @@
buffer += gp.sprint_var(func_name, indent=indent)
buffer += gp.sprint_varx("time_out", self.__time_out, indent=indent)
buffer += gp.sprint_varx("child_pid", self.__child_pid, indent=indent)
- buffer += gp.sprint_varx("original_SIGUSR1_handler",
- self.__original_SIGUSR1_handler,
- indent=indent)
+ buffer += gp.sprint_varx(
+ "original_SIGUSR1_handler",
+ self.__original_SIGUSR1_handler,
+ indent=indent,
+ )
return buffer
def print_obj(self):
@@ -95,8 +96,7 @@
if self.__original_SIGUSR1_handler != 0:
signal.signal(signal.SIGUSR1, self.__original_SIGUSR1_handler)
try:
- gp.lprint_timen("Killing child pid " + str(self.__child_pid)
- + ".")
+ gp.lprint_timen("Killing child pid " + str(self.__child_pid) + ".")
os.kill(self.__child_pid, signal.SIGKILL)
except OSError:
gp.lprint_timen("Tolerated kill failure.")
@@ -110,9 +110,7 @@
children = gm.get_child_pids()
gp.lprint_var(children)
- def timed_out(self,
- signal_number,
- frame):
+ def timed_out(self, signal_number, frame):
r"""
Handle a SIGUSR1 generated by the child process after the time_out has expired.
@@ -135,7 +133,6 @@
raise ValueError(err_msg)
def run(self, func, *args, **kwargs):
-
r"""
Run the indicated function with the given args and kwargs and return the value that the function
returns. If the time_out value expires, raise a ValueError exception with a detailed error message.
@@ -171,9 +168,9 @@
# Get self.__time_out value from kwargs. If kwargs['time_out'] is not present, self.__time_out will
# default to None.
self.__time_out = None
- if 'time_out' in kwargs:
- self.__time_out = kwargs['time_out']
- del kwargs['time_out']
+ if "time_out" in kwargs:
+ self.__time_out = kwargs["time_out"]
+ del kwargs["time_out"]
# Convert "none" string to None.
try:
if self.__time_out.lower() == "none":
@@ -183,12 +180,13 @@
if self.__time_out is not None:
self.__time_out = int(self.__time_out)
# Ensure that time_out is non-negative.
- message = gv.valid_range(self.__time_out, 0,
- var_name="time_out")
+ message = gv.valid_range(
+ self.__time_out, 0, var_name="time_out"
+ )
if message != "":
- raise ValueError("\n"
- + gp.sprint_error_report(message,
- format='long'))
+ raise ValueError(
+ "\n" + gp.sprint_error_report(message, format="long")
+ )
gp.lprint_varx("time_out", self.__time_out)
self.__child_pid = 0
@@ -200,13 +198,21 @@
parent_pid = os.getpid()
self.__child_pid = os.fork()
if self.__child_pid == 0:
- gp.dprint_timen("Child timer pid " + str(os.getpid())
- + ": Sleeping for " + str(self.__time_out)
- + " seconds.")
+ gp.dprint_timen(
+ "Child timer pid "
+ + str(os.getpid())
+ + ": Sleeping for "
+ + str(self.__time_out)
+ + " seconds."
+ )
time.sleep(self.__time_out)
- gp.dprint_timen("Child timer pid " + str(os.getpid())
- + ": Sending SIGUSR1 to parent pid "
- + str(parent_pid) + ".")
+ gp.dprint_timen(
+ "Child timer pid "
+ + str(os.getpid())
+ + ": Sending SIGUSR1 to parent pid "
+ + str(parent_pid)
+ + "."
+ )
os.kill(parent_pid, signal.SIGUSR1)
os._exit(0)