raspimjpeg: force restart of process if no communication
This commit is contained in:
parent
b93a8b2a70
commit
1da571bfef
|
@ -23,8 +23,8 @@ class raspimjpeg(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.__configfile = "/home/pi/PlanktonScope/scripts/raspimjpeg/raspimjpeg.conf"
|
self.__configfile = "/home/pi/PlanktonScope/scripts/raspimjpeg/raspimjpeg.conf"
|
||||||
self.__binary = "/home/pi/PlanktonScope/scripts/raspimjpeg/bin/raspimjpeg"
|
self.__binary = "/home/pi/PlanktonScope/scripts/raspimjpeg/bin/raspimjpeg"
|
||||||
self.__statusfile = "/dev/shm/mjpeg/status_mjpeg.txt"
|
self.__statusfile = "/dev/shm/mjpeg/status_mjpeg.txt" # nosec
|
||||||
self.__pipe = "/dev/shm/mjpeg/FIFO"
|
self.__pipe = "/dev/shm/mjpeg/FIFO" # nosec
|
||||||
self.__sensor_name = ""
|
self.__sensor_name = ""
|
||||||
|
|
||||||
# make sure the status file exists and is empty
|
# make sure the status file exists and is empty
|
||||||
|
@ -48,8 +48,19 @@ class raspimjpeg(object):
|
||||||
if not os.path.exists(self.__configfile):
|
if not os.path.exists(self.__configfile):
|
||||||
logger.error("The config file does not exists!")
|
logger.error("The config file does not exists!")
|
||||||
|
|
||||||
def start(self):
|
def start(self, force=False):
|
||||||
logger.debug("Starting up raspimjpeg")
|
logger.debug("Starting up raspimjpeg")
|
||||||
|
if force:
|
||||||
|
# let's kill all rogue Raspimjpeg first
|
||||||
|
try:
|
||||||
|
subprocess.run( # nosec
|
||||||
|
"sudo killall -9 raspimjpeg".split(),
|
||||||
|
shell=True,
|
||||||
|
timeout=1,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f"Killing Raspimjpeg failed because of {e}")
|
||||||
# The input to this call are perfectly controlled
|
# The input to this call are perfectly controlled
|
||||||
# hence the nosec comment to deactivate bandit error
|
# hence the nosec comment to deactivate bandit error
|
||||||
self.__process = subprocess.Popen( # nosec
|
self.__process = subprocess.Popen( # nosec
|
||||||
|
@ -70,6 +81,7 @@ class raspimjpeg(object):
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
||||||
)
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
try:
|
try:
|
||||||
width_string = self.__parse_output_for("Camera Max Width:")
|
width_string = self.__parse_output_for("Camera Max Width:")
|
||||||
|
@ -78,6 +90,8 @@ class raspimjpeg(object):
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
||||||
)
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
try:
|
try:
|
||||||
height_string = self.__parse_output_for("Camera Max Height")
|
height_string = self.__parse_output_for("Camera Max Height")
|
||||||
self.__height = height_string.rsplit(" ", 1)[1]
|
self.__height = height_string.rsplit(" ", 1)[1]
|
||||||
|
@ -85,6 +99,7 @@ class raspimjpeg(object):
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
||||||
)
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.__wait_for_output("Starting command loop")
|
self.__wait_for_output("Starting command loop")
|
||||||
|
@ -92,6 +107,7 @@ class raspimjpeg(object):
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
f"A timeout happened while waiting for RaspiMJPEG to start: {e}"
|
||||||
)
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
return self.__get_status()
|
return self.__get_status()
|
||||||
|
|
Loading…
Reference in a new issue