Skip to content

Commit

Permalink
Added optional argument to update camera status
Browse files Browse the repository at this point in the history
  • Loading branch information
teapot2 committed Nov 3, 2023
1 parent 8945431 commit 65a2127
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys


def get_cameras(skip_update=True):
def get_cameras(update_cameras=False):
"""
Retrieve camera objects from the API.
Expand Down Expand Up @@ -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"])

Expand Down
25 changes: 22 additions & 3 deletions create_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 65a2127

Please sign in to comment.