From 0d6e9122b43aebc20b9b482e64f298f9a9442120 Mon Sep 17 00:00:00 2001 From: livia-macon Date: Wed, 31 Jan 2024 16:38:10 -0300 Subject: [PATCH] FIX: Remove multiprocessing from find_multiple and a small tweak to _find_multiple_helper to return the coordinates. --- botcity/core/bot.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/botcity/core/bot.py b/botcity/core/bot.py index 0a21c29..ca12639 100644 --- a/botcity/core/bot.py +++ b/botcity/core/bot.py @@ -1,5 +1,4 @@ import functools -import multiprocessing import os import platform import psutil @@ -198,7 +197,6 @@ def _to_dict(lbs, elems): print('Warning: Ignoring best=False for now. It will be supported in the future.') start_time = time.time() - n_cpus = multiprocessing.cpu_count() - 1 while True: elapsed_time = (time.time() - start_time) * 1000 @@ -208,8 +206,7 @@ def _to_dict(lbs, elems): haystack = self.screenshot() helper = functools.partial(self._find_multiple_helper, haystack, region, matching, grayscale) - with multiprocessing.Pool(processes=n_cpus) as pool: - results = pool.map(helper, paths) + results = [helper(p) for p in paths] results = [self._fix_retina_element(r) for r in results] if None in results: @@ -238,6 +235,10 @@ def _fix_display_size(self): def _find_multiple_helper(self, haystack, region, confidence, grayscale, needle): ele = cv2find.locate_all_opencv(needle, haystack, region=region, confidence=confidence, grayscale=grayscale) + try: + ele = next(ele) + except StopIteration: + ele = None return ele def find(self, label, x=None, y=None, width=None, height=None, *, threshold=None,