Multi-processing per video stream
Change-Id: Ia8d64082261108ee548a6f7c56c40b51203e9322
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index 0998e1a..28ee57d 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -1,23 +1,22 @@
-import threading
-from queue import Queue
+from multiprocessing import Process, Queue
class BaseCamera(object):
- thread = {} # background thread that reads frames from camera
+ process = {} # background process that reads frames from camera
frame = {} # frame queue
def __init__(self, device=None, idle=False):
- """Start the background camera thread if it isn't running yet."""
+ """Start the background camera process if it isn't running yet."""
self.device = device
- if self.device not in BaseCamera.thread:
- BaseCamera.thread[self.device] = None
- if BaseCamera.thread[self.device] is None:
+ if self.device not in BaseCamera.process:
+ BaseCamera.process[self.device] = None
+ if BaseCamera.process[self.device] is None:
self.frame[device] = Queue(100)
- # start background frame thread
- BaseCamera.thread[self.device] = threading.Thread(target=self._thread, args=(self.device))
- BaseCamera.thread[self.device].start()
+ # start background frame process
+ BaseCamera.process[self.device] = Process(target=self._process, args=(self.device))
+ BaseCamera.process[self.device].start()
# wait until frames are available
_ = self.get_frame()
@@ -32,10 +31,10 @@
""""Generator that returns frames from the camera."""
raise NotImplementedError('Must be implemented by subclasses.')
- def _thread(self, device):
- """Camera background thread."""
+ def _process(self, device):
+ """Camera background process."""
frames_iterator = self.frames()
for frame in frames_iterator:
BaseCamera.frame[device].put(frame, block=True)
- BaseCamera.thread[device] = None
+ BaseCamera.process[device] = None