Skip to content

Commit

Permalink
Merge pull request #48 from botcity-dev/FIX/find-multiple
Browse files Browse the repository at this point in the history
FIX: Remove multiprocessing from find_multiple and a small tweak to _find_multiple_helper to return the coordinates.
  • Loading branch information
hhslepicka authored Feb 1, 2024
2 parents 85c2f68 + 0d6e912 commit 86c9cc9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions botcity/core/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import multiprocessing
import os
import platform
import psutil
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 86c9cc9

Please sign in to comment.