diff options
Diffstat (limited to 'worker.py')
| -rw-r--r-- | worker.py | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -27,6 +27,7 @@ from helpers import ( CustomLoggingFormatter, bytes_to_str, TIME_FORMAT_STRING, + auth_service, ) @@ -57,6 +58,7 @@ TMP_DIR = os.path.join(CWD, "tmp") CLIENTS_JSON_FILE = os.path.join(CWD, 'clients.json') # This should come from the config file: VIDEO_DIR = os.path.join(CWD, "videos") +CERTIFICATE_DIR = 'certs' # Other: @@ -177,8 +179,8 @@ class ServerWorker(Thread): ---------- identity : bytes Worker identity - context : zmq.Context, optional - ZMQ context (default is None, which creates a new context) + context : zmq.Context + ZMQ context Methods ------- @@ -189,7 +191,7 @@ class ServerWorker(Thread): run() Main loop of the worker. """ - def __init__(self, identity, context=None) -> None: + def __init__(self, identity, context) -> None: """ Docstring for __init__ @@ -197,11 +199,11 @@ class ServerWorker(Thread): ---------- identity : bytes Worker identity - context : zmq.Context, optional - ZMQ context (default is None, which creates a new context) + context : zmq.Context + ZMQ context """ super().__init__(daemon=True) - self.context = context or zmq.Context.instance() + self.context = context self.socket = self.context.socket(zmq.DEALER) self.id = self.socket.identity = identity self.monitor = MonitorTask(self.socket) @@ -241,7 +243,7 @@ class ServerWorker(Thread): if client_id not in self.video_threads or not self.video_threads[client_id].get(camera_id): q = Queue() logger.debug("Starting new video thread for client %r, camera %r", client_id, camera_id) - video_worker = VideoWorker(client_id, camera_id, filename, q) + video_worker = VideoWorker(client_id, camera_id, filename, q, self.context) video_worker.start() self.video_threads[client_id][camera_id] = video_worker @@ -490,7 +492,7 @@ class VideoWorker(Thread): Stop thread """ - def __init__(self, client_id, camera_id, filename, queue) -> None: + def __init__(self, client_id, camera_id, filename, queue, context) -> None: """ Docstring for __init__ @@ -504,9 +506,11 @@ class VideoWorker(Thread): Filename to write video to queue : Queue Queue to receive video frames + context : zmq.Context + ZMQ context """ super().__init__(daemon=True) - self.context = zmq.Context() + self.context = context self.context.setsockopt(zmq.LINGER, 0) self.client_id = client_id self.camera_id = camera_id @@ -625,7 +629,9 @@ if __name__ == "__main__": signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) - worker = ServerWorker(b"worker-task") + context = zmq.Context() + auth_service(context, CERTIFICATE_DIR) + worker = ServerWorker(b"worker-task", context) worker.start() worker.join() |
