diff --git a/api.py b/api.py index e2f2a21..e1ffc53 100644 --- a/api.py +++ b/api.py @@ -4,7 +4,7 @@ import sys -def get_cameras(skip_update=True): +def get_cameras(update_cameras=False): """ Retrieve camera objects from the API. @@ -32,7 +32,7 @@ def get_cameras(skip_update=True): print("\033[94m[i] Camera URLs retrieved successfully.\033[0m") - if skip_update == False: + if update_cameras == True: print("\033[94m[i] Pinging cameras...\n\033[0m") ping_cameras(cameras=response["data"]) diff --git a/create_threads.py b/create_threads.py index 7a27dc9..be3e0d1 100644 --- a/create_threads.py +++ b/create_threads.py @@ -7,6 +7,7 @@ import time import os import signal +import argparse import sys # Lambda function for generating shared memory stream names based on index @@ -117,8 +118,15 @@ def process_camera(index, url, name, shared_dict): ) # Close the shared memory segment in case of an error - shm.close() - shm.unlink() + terminate_shm(shm) + + finally: + terminate_shm(shm) + + +def terminate_shm(shm): + shm.close() + shm.unlink() # Function for monitoring the status of the camera processes @@ -192,11 +200,22 @@ def close_threads(urls): signal.signal(signal.SIGINT, signal_handler) + parser = argparse.ArgumentParser() + parser.add_argument( + "-U", + "--update", + action="store_true", + default=False, + help="Specify this flag to skip camera updates", + ) + + args = parser.parse_args() + # Use a manager for shared dictionary with Manager() as manager: shared_dict = manager.dict() - cameras = get_cameras(skip_update=True) + cameras = get_cameras(update_cameras=args.update) urls = [ camera["camera_url"]