From 2c9a5f7dfa806b186616d425554b052b8981ff43 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 25 Aug 2022 11:17:38 +0200 Subject: [PATCH] Startup --- script/test/test_thread.py | 81 +++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/script/test/test_thread.py b/script/test/test_thread.py index 6ef38a0..9e529d9 100644 --- a/script/test/test_thread.py +++ b/script/test/test_thread.py @@ -1,10 +1,12 @@ import threading +import sys import queue import traceback from bsread import source, Source, PUB, SUB, PUSH, PULL, DEFAULT_DISPATCHER_URL from cam_server.pipeline.configuration import PipelineConfig -#from processing import run as processing_pipeline +from cam_server import CamClient, PipelineClient, ProxyClient, config from cam_server.pipeline.types.processing import run as processing_pipeline +import multiprocessing class Namespace(object): def __init__(self, **kwds): @@ -17,10 +19,40 @@ class Namespace(object): temp.append('%s=%r' % (name, value)) temp.sort() return 'Namespace(%s)' % str.join(', ', temp) - -statistics=Namespace() -pipeline_config = PipelineConfig("test_pipeline", parameters={"camera_name": "simulation", "function":"transparent"}) +class MockBackgroundManager: + def __init__(self): + self.backgrounds = {} + + def get_background(self, background_name): + if not background_name: + return None + if background_name not in self.backgrounds: + raise ValueError("Requested background '%s' does not exist." % background_name) + return self.backgrounds[background_name] + + def save_background(self, background_name, image, append_timestamp=True): + if append_timestamp: + background_name += datetime.now().strftime("_%Y%m%d_%H%M%S_%f") + self.backgrounds[background_name] = image + return background_name + + def get_latest_background_id(self, background_prefix): + raise NotImplementedError("This cannot work in the mock.") + + def get_background_ids(self, background_prefix): + raise NotImplementedError("This cannot work in the mock.") + + + +statistics= Namespace() +pipeline_config = PipelineConfig("test_pipeline", parameters={"camera_name": "simulation", "function":"transparent"}) +camera_client = CamClient("http://localhost:8888" ) + +def dont_exit(status): + print ("System Exit status: ", status) +sys.exit = dont_exit + def run_pipeline(port, pipeline_config, parameter_queue, stop_event): print ("Startint pipeline on port: ", port) @@ -35,33 +67,38 @@ def get_data(port): data = stream.receive() if not data: raise Exception("Received None message.") - print (data.data.data.keys()) + return data.data.data -OUTPUT_PORT = 12005 +for port in (12007, 12008): + print ( "--------------------------------------") + print ("Port: ", port) + stop_event = threading.Event() + parameter_queue = queue.Queue() + thread = threading.Thread(target=run_pipeline, args=(port,pipeline_config, parameter_queue, stop_event)) + thread.start() + data = get_data(port) + print ("Received: ", data.keys()) + stop_event.set() + thread.join(5.0) + print ("Finished OK") + + + + + + +""" +OUTPUT_PORT = 12008 stop_event = threading.Event() parameter_queue = queue.Queue() thread = threading.Thread(target=run_pipeline, args=(OUTPUT_PORT,pipeline_config, parameter_queue, stop_event)) -thread.start() +thread.start()' get_data(OUTPUT_PORT) stop_event.set() thread.join(5.0) print ("Done") - - - - -OUTPUT_PORT = 12006 -stop_event = threading.Event() -parameter_queue = queue.Queue() -thread = threading.Thread(target=run_pipeline, args=(OUTPUT_PORT,pipeline_config, parameter_queue, stop_event)) -thread.start() -get_data(OUTPUT_PORT) -stop_event.set() -thread.join(5.0) -print ("Done") - - +"""