from ITS.api import gather_cctv_list from hls_streaming.hls import FrameCapturer from time import sleep import threading from time import sleep import pandas as pd def manage_capturer(): # cctv_list1 = pd.read_csv("ITS/list/125_130_y33_39.csv") cctv_list = pd.read_csv("ITS/list/128.07439272_130.909268695_y35.635147801_37.497349441_its.csv") # cctv_list = pd.concat((cctv_list1, cctv_list2)) cctv_list = cctv_list.sample(frac=1).reset_index(drop=True) cctv_list_name = cctv_list['cctvname'] cctv_list_url = cctv_list['cctvurl'] for (name, url) in zip(cctv_list_name, cctv_list_url): try: frame_cap = FrameCapturer(url, name, "_", "_") frame_cap.start() sleep(50) frame_cap.stop() sleep(60) except: continue # Create threads for the first 10 capturers (assuming there are at least 10) threads = [threading.Thread(target=manage_capturer) for _ in range(3)] # Start all threads for thread in threads: thread.start() sleep(1) # Wait for all threads to finish for thread in threads: thread.join()