From 339004033f1c0357aa9a597ff7ba947577580d68 Mon Sep 17 00:00:00 2001 From: ShinoAce Date: Sun, 24 Jan 2021 17:46:28 +0100 Subject: [PATCH] Fixed exception not rethrown in webcamvideostream Fixed FATAL: exception not rethrown in webcamvideostream #237 --- imutils/video/webcamvideostream.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/imutils/video/webcamvideostream.py b/imutils/video/webcamvideostream.py index dbe8751..6a64841 100644 --- a/imutils/video/webcamvideostream.py +++ b/imutils/video/webcamvideostream.py @@ -11,6 +11,9 @@ def __init__(self, src=0, name="WebcamVideoStream"): # initialize the thread name self.name = name + + # create a thread + self.thread = None # initialize the variable used to indicate if the thread should # be stopped @@ -18,9 +21,9 @@ def __init__(self, src=0, name="WebcamVideoStream"): def start(self): # start the thread to read frames from the video stream - t = Thread(target=self.update, name=self.name, args=()) - t.daemon = True - t.start() + self.thread = Thread(target=self.update, name=self.name, args=()) + self.thread.daemon = True + self.thread.start() return self def update(self): @@ -40,3 +43,7 @@ def read(self): def stop(self): # indicate that the thread should be stopped self.stopped = True + # wait until stream resources are released (producer thread might be still grabbing frame) + if self.thread is not None: + self.thread.join() + # properly handle stop the thread