From 0c77ad0121ccaf3d52e19a6e20a1c431a9e60c7a Mon Sep 17 00:00:00 2001 From: Siraj Qazi Date: Sat, 9 Jan 2021 06:19:34 +0500 Subject: [PATCH] Fixed FATAL: exception not rethrown in webcamvideostream Fixed the threading issue mentioned in #164 (https://github.com/jrosebr1/imutils/issues/164) in webcamvideostream.py that was closed as a cv2 bug. --- imutils/video/webcamvideostream.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/imutils/video/webcamvideostream.py b/imutils/video/webcamvideostream.py index dbe8751..b341568 100644 --- a/imutils/video/webcamvideostream.py +++ b/imutils/video/webcamvideostream.py @@ -11,6 +11,10 @@ def __init__(self, src=0, name="WebcamVideoStream"): # initialize the thread name self.name = name + + # intialize thread + self.thread = Thread(target=self.update, name=self.name, args=()) + self.thread.daemon = True # initialize the variable used to indicate if the thread should # be stopped @@ -18,9 +22,8 @@ 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.start() return self def update(self): @@ -40,3 +43,6 @@ 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) + self.thread.join()