better manage a segmenter failure to start and kill the process
This commit is contained in:
parent
bd85bc0d28
commit
1cf9874391
|
@ -66,6 +66,7 @@ run = True
|
||||||
def handler_stop_signals(signum, frame):
|
def handler_stop_signals(signum, frame):
|
||||||
"""This handler simply stop the forever running loop in __main__"""
|
"""This handler simply stop the forever running loop in __main__"""
|
||||||
global run
|
global run
|
||||||
|
logger.info(f"Received a signal asking to stop {signum}")
|
||||||
run = False
|
run = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,10 +132,15 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# Starts the segmenter process
|
# Starts the segmenter process
|
||||||
logger.info("Starting the segmenter control process (step 4/4)")
|
logger.info("Starting the segmenter control process (step 4/4)")
|
||||||
segmenter_thread = planktoscope.segmenter.SegmenterProcess(
|
try:
|
||||||
shutdown_event, "/home/pi/data"
|
segmenter_thread = planktoscope.segmenter.SegmenterProcess(
|
||||||
)
|
shutdown_event, "/home/pi/data"
|
||||||
segmenter_thread.start()
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("The segmenter control process could not be started")
|
||||||
|
else:
|
||||||
|
segmenter_thread = None
|
||||||
|
segmenter_thread.start()
|
||||||
|
|
||||||
# Starts the module process
|
# Starts the module process
|
||||||
# Uncomment here as needed
|
# Uncomment here as needed
|
||||||
|
@ -154,28 +160,34 @@ if __name__ == "__main__":
|
||||||
if not stepper_thread.is_alive():
|
if not stepper_thread.is_alive():
|
||||||
logger.error("The stepper process died unexpectedly! Oh no!")
|
logger.error("The stepper process died unexpectedly! Oh no!")
|
||||||
break
|
break
|
||||||
if imager_thread and not imager_thread.is_alive():
|
if not imager_thread or not imager_thread.is_alive():
|
||||||
logger.error("The imager process died unexpectedly! Oh no!")
|
logger.error("The imager process died unexpectedly! Oh no!")
|
||||||
break
|
break
|
||||||
if not segmenter_thread.is_alive():
|
if not segmenter_thread or not segmenter_thread.is_alive():
|
||||||
logger.error("The segmenter process died unexpectedly! Oh no!")
|
logger.error("The segmenter process died unexpectedly! Oh no!")
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
display.display_text("Bye Bye!")
|
display.display_text("Bye Bye!")
|
||||||
logger.info("Shutting down the shop")
|
logger.info("Shutting down the shop")
|
||||||
shutdown_event.set()
|
shutdown_event.set()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
stepper_thread.join()
|
stepper_thread.join()
|
||||||
if imager_thread:
|
if imager_thread:
|
||||||
imager_thread.join()
|
imager_thread.join()
|
||||||
segmenter_thread.join()
|
if segmenter_thread:
|
||||||
|
segmenter_thread.join()
|
||||||
# Uncomment this for clean shutdown
|
# Uncomment this for clean shutdown
|
||||||
# module_thread.join()
|
# module_thread.join()
|
||||||
|
|
||||||
stepper_thread.close()
|
stepper_thread.close()
|
||||||
if imager_thread:
|
if imager_thread:
|
||||||
imager_thread.close()
|
imager_thread.close()
|
||||||
segmenter_thread.close()
|
if segmenter_thread:
|
||||||
|
segmenter_thread.close()
|
||||||
# Uncomment this for clean shutdown
|
# Uncomment this for clean shutdown
|
||||||
# module_thread.close()
|
# module_thread.close()
|
||||||
|
|
||||||
display.stop()
|
display.stop()
|
||||||
logger.info("Bye")
|
logger.info("Bye")
|
||||||
|
|
|
@ -954,7 +954,14 @@ class SegmenterProcess(multiprocessing.Process):
|
||||||
handler = functools.partial(
|
handler = functools.partial(
|
||||||
planktoscope.segmenter.streamer.StreamingHandler, refresh_delay
|
planktoscope.segmenter.streamer.StreamingHandler, refresh_delay
|
||||||
)
|
)
|
||||||
server = planktoscope.segmenter.streamer.StreamingServer(address, handler)
|
try:
|
||||||
|
server = planktoscope.segmenter.streamer.StreamingServer(address, handler)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(
|
||||||
|
f"An exception has occured when starting up the segmenter: {e}"
|
||||||
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
self.streaming_thread = threading.Thread(
|
self.streaming_thread = threading.Thread(
|
||||||
target=server.serve_forever, daemon=True
|
target=server.serve_forever, daemon=True
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue