Idle mode
Change-Id: I43f80aab51ae01e544bda6ffb9fb7990d359564d
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index 88a1e0e..90a2474 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -56,10 +56,12 @@
frame = {} # current frame is stored here by background thread
last_access = {} # time of last client access to the camera
event = {}
+ idle = False # if True, stops thread if no client connected
- def __init__(self, device=None):
+ def __init__(self, device=None, idle=False):
"""Start the background camera thread if it isn't running yet."""
self.device = device
+ self.idle = idle
BaseCamera.event[self.device] = CameraEvent()
if self.device not in BaseCamera.thread:
BaseCamera.thread[self.device] = None
@@ -96,10 +98,12 @@
BaseCamera.event[device].set() # send signal to clients
time.sleep(0)
- # if there hasn't been any clients asking for frames in
- # the last 10 seconds then stop the thread
- if time.time() - BaseCamera.last_access[device] > 10:
- frames_iterator.close()
- print('Stopping camera thread due to inactivity.')
- break
+ if self.idle:
+ # if there hasn't been any clients asking for frames in
+ # the last 10 seconds then stop the thread
+ if time.time() - BaseCamera.last_access[device] > 10:
+ frames_iterator.close()
+ print('Stopping camera thread due to inactivity.')
+ break
+
BaseCamera.thread[device] = None