diff --git a/src/main/java/ai/nets/samj/models/Sam2.java b/src/main/java/ai/nets/samj/models/Sam2.java index ea33bb9..6585da6 100644 --- a/src/main/java/ai/nets/samj/models/Sam2.java +++ b/src/main/java/ai/nets/samj/models/Sam2.java @@ -442,8 +442,14 @@ protected void processPromptsBatchWithSAM(SharedMemoryArray shmArr, boolean retu String code = "" + "num_threads = 3" + System.lineSeparator() + "finished_threads = []" + System.lineSeparator() - + "from concurrent.futures import ThreadPoolExecutor, as_completed" + System.lineSeparator() - + "import threading" + System.lineSeparator() + + "print(('threading' not in globals().keys()))" + System.lineSeparator() + + "if \"threading\" not in globals().keys():" + System.lineSeparator() + + " import threading" + System.lineSeparator() + + " globals()['threading'] = threading" + System.lineSeparator() + + "if \"ThreadPoolExecutor\" not in globals().keys():" + System.lineSeparator() + + " from concurrent.futures import ThreadPoolExecutor, as_completed" + System.lineSeparator() + + " globals()['ThreadPoolExecutor'] = ThreadPoolExecutor" + System.lineSeparator() + + " globals()['as_completed'] = as_completed" + System.lineSeparator() + "lock = threading.Lock()" + System.lineSeparator() + "def respond_in_thread(task, args, inds, lock, finished_threads):" + System.lineSeparator() + " task._respond(ResponseType.UPDATE, args)" + System.lineSeparator()