Code cleanup

This commit is contained in:
2022-04-02 21:45:47 +02:00
parent b7f4004abb
commit cbfd69d852
2 changed files with 19 additions and 17 deletions

View File

@@ -1,6 +1,17 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" /> <option name="LINE_SEPARATOR" value="&#10;" />
<option name="RIGHT_MARGIN" value="80" /> <Python>
<option name="OPTIMIZE_IMPORTS_SORT_NAMES_IN_FROM_IMPORTS" value="true" />
</Python>
<codeStyleSettings language="Markdown">
<option name="RIGHT_MARGIN" value="80" />
<option name="WRAP_ON_TYPING" value="1" />
</codeStyleSettings>
<codeStyleSettings language="Shell Script">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme> </code_scheme>
</component> </component>

View File

@@ -9,7 +9,7 @@ from fcntl import ioctl
from random import random from random import random
from struct import pack, unpack from struct import pack, unpack
from subprocess import Popen from subprocess import Popen
from threading import Thread, Event from threading import Event, Thread
from time import time from time import time
import proginit as pi import proginit as pi
@@ -45,7 +45,6 @@ class SoftwareWatchdog:
pi.logger.debug("enter SoftwareWatchdog.__th_run()") pi.logger.debug("enter SoftwareWatchdog.__th_run()")
# Startup delay to let the python program start and trigger # Startup delay to let the python program start and trigger
# todo: Is this fix value okay?
if self._exit.wait(2.0): if self._exit.wait(2.0):
pi.logger.debug("leave SoftwareWatchdog.__th_run()") pi.logger.debug("leave SoftwareWatchdog.__th_run()")
return return
@@ -74,9 +73,7 @@ class SoftwareWatchdog:
self.triggered = True self.triggered = True
if self._process is not None: if self._process is not None:
self._process.kill() self._process.kill()
pi.logger.warning( pi.logger.warning("process killed by software watchdog")
"process killed by software watchdog"
)
break break
os.close(fd) os.close(fd)
@@ -147,9 +144,7 @@ class SoftwareWatchdog:
if not isinstance(value, int): if not isinstance(value, int):
raise TypeError("timeout must be <class 'int'>") raise TypeError("timeout must be <class 'int'>")
if value < 0: if value < 0:
raise ValueError( raise ValueError("timeout value must be 0 to disable or a positive number")
"timeout value must be 0 to disable or a positive number"
)
if value == 0: if value == 0:
# A value of 0 will stop the watchdog thread # A value of 0 will stop the watchdog thread
@@ -161,15 +156,11 @@ class SoftwareWatchdog:
self._timeout = 0.0 self._timeout = 0.0
else: else:
self._timeout = float(value) self._timeout = float(value)
if not (self.triggered or if not (self.triggered or self._stopped or self.__th.is_alive()):
self._stopped or self.__th.is_alive()):
self._exit.clear() self._exit.clear()
self.__th = Thread(target=self.__th_run) self.__th = Thread(target=self.__th_run)
self.__th.start() self.__th.start()
pi.logger.debug( pi.logger.debug("set software watchdog timeout to {0} seconds".format(value))
"set software watchdog timeout to {0} seconds"
"".format(value)
)
class ResetDriverWatchdog(Thread): class ResetDriverWatchdog(Thread):
@@ -201,8 +192,8 @@ class ResetDriverWatchdog(Thread):
except Exception: except Exception:
self.not_implemented = True self.not_implemented = True
pi.logger.error( pi.logger.error(
"can not open process image at '{0}' for piCtory " "can not open process image at '{0}' for piCtory reset_driver watchdog"
"reset_driver watchdog".format(pi.pargs.procimg) "".format(pi.pargs.procimg)
) )
return return