Skip to content

Commit 86c9cc9

Browse files
authored
Merge pull request #48 from botcity-dev/FIX/find-multiple
FIX: Remove multiprocessing from find_multiple and a small tweak to _find_multiple_helper to return the coordinates.
2 parents 85c2f68 + 0d6e912 commit 86c9cc9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

botcity/core/bot.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import functools
2-
import multiprocessing
32
import os
43
import platform
54
import psutil
@@ -198,7 +197,6 @@ def _to_dict(lbs, elems):
198197
print('Warning: Ignoring best=False for now. It will be supported in the future.')
199198

200199
start_time = time.time()
201-
n_cpus = multiprocessing.cpu_count() - 1
202200

203201
while True:
204202
elapsed_time = (time.time() - start_time) * 1000
@@ -208,8 +206,7 @@ def _to_dict(lbs, elems):
208206
haystack = self.screenshot()
209207
helper = functools.partial(self._find_multiple_helper, haystack, region, matching, grayscale)
210208

211-
with multiprocessing.Pool(processes=n_cpus) as pool:
212-
results = pool.map(helper, paths)
209+
results = [helper(p) for p in paths]
213210

214211
results = [self._fix_retina_element(r) for r in results]
215212
if None in results:
@@ -238,6 +235,10 @@ def _fix_display_size(self):
238235
def _find_multiple_helper(self, haystack, region, confidence, grayscale, needle):
239236
ele = cv2find.locate_all_opencv(needle, haystack, region=region,
240237
confidence=confidence, grayscale=grayscale)
238+
try:
239+
ele = next(ele)
240+
except StopIteration:
241+
ele = None
241242
return ele
242243

243244
def find(self, label, x=None, y=None, width=None, height=None, *, threshold=None,

0 commit comments

Comments
 (0)