From 8732f8729f45c99e0a01cf8cd2965929ee799ae9 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Wed, 2 Jun 2021 14:07:40 +0200 Subject: [PATCH] segmenter: don't push to pipe if the pipe if full (cherry picked from commit 1c5a94e605f7ab52efc6fb2b2fdeefdf2c4ab2e3) --- scripts/planktoscope/segmenter/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/planktoscope/segmenter/__init__.py b/scripts/planktoscope/segmenter/__init__.py index 684357d..8d3ee4f 100644 --- a/scripts/planktoscope/segmenter/__init__.py +++ b/scripts/planktoscope/segmenter/__init__.py @@ -390,12 +390,17 @@ class SegmenterProcess(multiprocessing.Process): } def _stream(self, img): + def pipe_full(conn): + r, w, x = select.select([], [conn], [], 0.0) + return len(w) == 0 + img_object = io.BytesIO() PIL.Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)).save( img_object, format="JPEG" ) logger.debug("Sending the object in the pipe!") - planktoscope.segmenter.streamer.sender.send(img_object) + if not pipe_full(planktoscope.segmenter.streamer.sender): + planktoscope.segmenter.streamer.sender.send(img_object) def _slice_image(self, img, name, mask, start_count=0): """Slice a given image using give mask