Skip to content

Commit

Permalink
avoid importing all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 3, 2024
1 parent 37eae2c commit b4bbf1b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/ai/nets/samj/models/Sam2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b4bbf1b

Please sign in to comment.