cleanup detection shms

This commit is contained in:
Blake Blackshear 2020-10-11 09:40:20 -05:00
parent 12c4cd77c5
commit e4da3822b1
2 changed files with 11 additions and 3 deletions

View File

@ -174,10 +174,15 @@ def main():
# Queue for clip processing
event_queue = mp.Queue()
# create the detection pipes
# create the detection pipes and shms
out_events = {}
camera_shms = []
for name in CONFIG['cameras'].keys():
out_events[name] = mp.Event()
shm_in = mp.shared_memory.SharedMemory(name=name, create=True, size=300*300*3)
shm_out = mp.shared_memory.SharedMemory(name=f"out-{name}", create=True, size=20*6*4)
camera_shms.append(shm_in)
camera_shms.append(shm_out)
detection_queue = mp.Queue()
@ -302,6 +307,9 @@ def main():
camera_process['capture_thread'].join()
for detector in detectors:
detector.stop()
for shm in camera_shms:
shm.close()
shm.unlink()
sys.exit()
signal.signal(signal.SIGTERM, receiveSignal)

View File

@ -165,9 +165,9 @@ class RemoteObjectDetector():
self.fps = EventsPerSecond()
self.detection_queue = detection_queue
self.event = event
self.shm = mp.shared_memory.SharedMemory(name=self.name, create=True, size=300*300*3)
self.shm = mp.shared_memory.SharedMemory(name=self.name, create=False)
self.np_shm = np.ndarray((1,300,300,3), dtype=np.uint8, buffer=self.shm.buf)
self.out_shm = mp.shared_memory.SharedMemory(name=f"out-{self.name}", create=True, size=20*6*4)
self.out_shm = mp.shared_memory.SharedMemory(name=f"out-{self.name}", create=False)
self.out_np_shm = np.ndarray((20,6), dtype=np.float32, buffer=self.out_shm.buf)
def detect(self, tensor_input, threshold=.4):