python: improve log messages
This commit is contained in:
parent
2c9a6df20f
commit
1a42f05941
|
@ -123,7 +123,7 @@ if __name__ == "__main__":
|
||||||
segmenter_thread = planktoscope.segmenter.SegmenterProcess(shutdown_event)
|
segmenter_thread = planktoscope.segmenter.SegmenterProcess(shutdown_event)
|
||||||
segmenter_thread.start()
|
segmenter_thread.start()
|
||||||
|
|
||||||
logger.info("Looks like everything is set up and running, have fun!")
|
logger.success("Looks like everything is set up and running, have fun!")
|
||||||
|
|
||||||
while run:
|
while run:
|
||||||
# TODO look into ways of restarting the dead threads
|
# TODO look into ways of restarting the dead threads
|
||||||
|
@ -141,6 +141,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
logger.info("Shutting down the shop")
|
logger.info("Shutting down the shop")
|
||||||
shutdown_event.set()
|
shutdown_event.set()
|
||||||
|
time.sleep(0.5)
|
||||||
stepper_thread.join()
|
stepper_thread.join()
|
||||||
imager_thread.join()
|
imager_thread.join()
|
||||||
segmenter_thread.join()
|
segmenter_thread.join()
|
||||||
|
|
|
@ -162,7 +162,7 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
# FIXME We should save the metadata to a file in the folder too
|
# FIXME We should save the metadata to a file in the folder too
|
||||||
# TODO create a directory structure per day/per imaging session
|
# TODO create a directory structure per day/per imaging session
|
||||||
|
|
||||||
logger.info("planktoscope.imager is initialised and ready to go!")
|
logger.success("planktoscope.imager is initialised and ready to go!")
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def start_camera(self):
|
def start_camera(self):
|
||||||
|
@ -401,8 +401,9 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
# Define the filename of the image
|
# Define the filename of the image
|
||||||
filename_path = os.path.join(self.__export_path, filename)
|
filename_path = os.path.join(self.__export_path, filename)
|
||||||
|
|
||||||
logger.info(f"Capturing an image to {filename_path}")
|
logger.info(
|
||||||
# TODO Insert here a delay to stabilize the flow before we image
|
f"Capturing image {self.__img_done + 1}/{self.__img_goal} to {filename_path}"
|
||||||
|
)
|
||||||
|
|
||||||
# Capture an image with the proper filename
|
# Capture an image with the proper filename
|
||||||
self.__camera.capture(filename_path)
|
self.__camera.capture(filename_path)
|
||||||
|
@ -413,7 +414,7 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
# Publish the name of the image to via MQTT to Node-RED
|
# Publish the name of the image to via MQTT to Node-RED
|
||||||
self.imager_client.client.publish(
|
self.imager_client.client.publish(
|
||||||
"status/imager",
|
"status/imager",
|
||||||
f'{{"status":"{self.__img_done + 1}/{self.__img_goal} has been imaged to {filename}."}}',
|
f'{{"status":"Image {self.__img_done + 1}/{self.__img_goal} has been imaged to {filename}"}}',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Increment the counter
|
# Increment the counter
|
||||||
|
@ -483,6 +484,9 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
topic="imager/#", name="imager_client"
|
topic="imager/#", name="imager_client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.imager_client.client.publish("status/imager", '{"status":"Starting up"}')
|
||||||
|
|
||||||
|
logger.info("Initialising the camera")
|
||||||
# PiCamera settings
|
# PiCamera settings
|
||||||
self.__camera = picamera.PiCamera(resolution=self.__resolution)
|
self.__camera = picamera.PiCamera(resolution=self.__resolution)
|
||||||
self.__camera.iso = self.__iso
|
self.__camera.iso = self.__iso
|
||||||
|
@ -502,7 +506,7 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
# Publish the status "Ready" to via MQTT to Node-RED
|
# Publish the status "Ready" to via MQTT to Node-RED
|
||||||
self.imager_client.client.publish("status/imager", '{"status":"Ready"}')
|
self.imager_client.client.publish("status/imager", '{"status":"Ready"}')
|
||||||
|
|
||||||
logger.info("Let's rock and roll!")
|
logger.success("Camera is READY!")
|
||||||
|
|
||||||
# This is the loop
|
# This is the loop
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
|
@ -517,6 +521,8 @@ class ImagerProcess(multiprocessing.Process):
|
||||||
self.__camera.close()
|
self.__camera.close()
|
||||||
logger.debug("Stopping the streaming thread")
|
logger.debug("Stopping the streaming thread")
|
||||||
server.shutdown()
|
server.shutdown()
|
||||||
|
logger.debug("Stopping MQTT")
|
||||||
self.imager_client.shutdown()
|
self.imager_client.shutdown()
|
||||||
# self.streaming_thread.kill()
|
# self.streaming_thread.kill()
|
||||||
logger.info("Imager process shut down! See you!")
|
logger.success("Imager process shut down! See you!")
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class SegmenterProcess(multiprocessing.Process):
|
||||||
os.makedirs(self.__ecotaxa_path)
|
os.makedirs(self.__ecotaxa_path)
|
||||||
# Morphocut's pipeline will be created at runtime otherwise shit ensues
|
# Morphocut's pipeline will be created at runtime otherwise shit ensues
|
||||||
|
|
||||||
logger.info("planktoscope.segmenter is initialised and ready to go!")
|
logger.success("planktoscope.segmenter is initialised and ready to go!")
|
||||||
|
|
||||||
def __create_morphocut_pipeline(self):
|
def __create_morphocut_pipeline(self):
|
||||||
"""Creates the Morphocut Pipeline"""
|
"""Creates the Morphocut Pipeline"""
|
||||||
|
@ -349,7 +349,7 @@ class SegmenterProcess(multiprocessing.Process):
|
||||||
# Publish the status "Ready" to via MQTT to Node-RED
|
# Publish the status "Ready" to via MQTT to Node-RED
|
||||||
self.segmenter_client.client.publish("status/segmenter", '{"status":"Ready"}')
|
self.segmenter_client.client.publish("status/segmenter", '{"status":"Ready"}')
|
||||||
|
|
||||||
logger.info("Ready to roll!")
|
logger.success("Segmenter is READY!")
|
||||||
|
|
||||||
# This is the loop
|
# This is the loop
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
|
@ -359,4 +359,5 @@ class SegmenterProcess(multiprocessing.Process):
|
||||||
logger.info("Shutting down the segmenter process")
|
logger.info("Shutting down the segmenter process")
|
||||||
self.segmenter_client.client.publish("status/segmenter", '{"status":"Dead"}')
|
self.segmenter_client.client.publish("status/segmenter", '{"status":"Dead"}')
|
||||||
self.segmenter_client.shutdown()
|
self.segmenter_client.shutdown()
|
||||||
logger.info("Segmenter process shut down! See you!")
|
logger.success("Segmenter process shut down! See you!")
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
|
|
||||||
def __init__(self, event):
|
def __init__(self, event):
|
||||||
super(StepperProcess, self).__init__()
|
super(StepperProcess, self).__init__()
|
||||||
|
logger.info("Initialising the stepper process")
|
||||||
|
|
||||||
self.stop_event = event
|
self.stop_event = event
|
||||||
|
|
||||||
|
@ -244,7 +245,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
logger.error(f"{self.stepper_type} is what was supplied")
|
logger.error(f"{self.stepper_type} is what was supplied")
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f"Stepper initialisation is over")
|
logger.info(f"Stepper initialisation is over")
|
||||||
|
|
||||||
def treat_command(self):
|
def treat_command(self):
|
||||||
command = ""
|
command = ""
|
||||||
|
@ -495,6 +496,8 @@ class StepperProcess(multiprocessing.Process):
|
||||||
self.actuator_client.client.publish("status/pump", '{"status":"Ready"}')
|
self.actuator_client.client.publish("status/pump", '{"status":"Ready"}')
|
||||||
# Publish the status "Ready" to via MQTT to Node-RED
|
# Publish the status "Ready" to via MQTT to Node-RED
|
||||||
self.actuator_client.client.publish("status/focus", '{"status":"Ready"}')
|
self.actuator_client.client.publish("status/focus", '{"status":"Ready"}')
|
||||||
|
|
||||||
|
logger.success("Stepper is READY!")
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
# check if a new message has been received
|
# check if a new message has been received
|
||||||
self.treat_command()
|
self.treat_command()
|
||||||
|
@ -515,7 +518,7 @@ class StepperProcess(multiprocessing.Process):
|
||||||
self.pump_stepper.shutdown()
|
self.pump_stepper.shutdown()
|
||||||
self.focus_stepper.shutdown()
|
self.focus_stepper.shutdown()
|
||||||
self.actuator_client.shutdown()
|
self.actuator_client.shutdown()
|
||||||
logger.info("Stepper process shut down! See you!")
|
logger.success("Stepper process shut down! See you!")
|
||||||
|
|
||||||
|
|
||||||
# This is called if this script is launched directly
|
# This is called if this script is launched directly
|
||||||
|
|
Loading…
Reference in a new issue