Skip to content

Commit

Permalink
fix: fixed streams not closing when trackers stop
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Jan 5, 2024
1 parent 18cb6b1 commit 871024c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion TrackingBackend/app/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class Tracker:
def __init__(self, config: EyeTrackConfig, uuid: str, manager: SyncManager, router: APIRouter):
self.uuid = uuid
self.router = router
self.config = config
self.tracker_config = config.get_tracker_by_uuid(uuid)
self.router = router
# IPC stuff
self.manager = manager
self.osc_queue: Queue[EyeData] = self.manager.Queue()
Expand All @@ -40,9 +40,13 @@ def stop(self) -> None:
self.camera.stop()
self.processor.stop()
self.osc_sender.stop()
self.camera_visualizer.stop()
self.algorithm_visualizer.stop()
# if we dont do this we memory leak :3
clear_queue(self.osc_queue)
clear_queue(self.image_queue)
clear_queue(self.camera_queue)
clear_queue(self.algo_frame_queue)

def restart(self) -> None:
self.camera.restart()
Expand Down
6 changes: 5 additions & 1 deletion TrackingBackend/app/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
class Visualizer:
def __init__(self, image_queue: Queue):
self.image_queue: Queue = image_queue
self.running: bool = True

def gen_frame(self):
while True:
while self.running:
try:
frame = self.image_queue.get(timeout=1)
except Exception:
Expand All @@ -22,5 +23,8 @@ def gen_frame(self):
def video_feed(self) -> StreamingResponse:
return StreamingResponse(self.gen_frame(), media_type="multipart/x-mixed-replace; boundary=frame")

def stop(self):
self.running = False

def __call__(self, *args: Any, **kwds: Any) -> StreamingResponse:
return self.video_feed()

0 comments on commit 871024c

Please sign in to comment.