Pārlūkot izejas kodu

add threading control to analyzer

Kirk Trombley 2 gadi atpakaļ
vecāks
revīzija
6cfbd3c213
1 mainītis faili ar 5 papildinājumiem un 3 dzēšanām
  1. 5 3
      tools/analyze.py

+ 5 - 3
tools/analyze.py

@@ -268,6 +268,9 @@ if __name__ == "__main__":
   parser.add_argument(
     "-d", "--pokedex", default="data/pokedex.json", help="Pokedex file"
   )
+  parser.add_argument(
+    "--threading", action="store_true", help="Use threads instead of multiproc (slower but more stable on 3.10)"
+  )
   parser.add_argument("images", metavar="file", type=Path, nargs="+")
 
   args = parser.parse_args()
@@ -277,7 +280,6 @@ if __name__ == "__main__":
 
   ingest = Ingester(dex, args.precision, args.seed)
 
-  from concurrent.futures import ProcessPoolExecutor
-  from multiprocessing import get_context
-  with ProcessPoolExecutor(max_workers=args.workers, mp_context=get_context("spawn")) as pool:
+  from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
+  with (ThreadPoolExecutor if args.threading else ProcessPoolExecutor)(max_workers=args.workers) as pool:
     run_ingest(ingest, args.images, pool, args.output)