-1

I want to know if is there a way to make multiprocessing working in this code. What should I change or if there exist other function in multiprocessing that will allow me to do that operation.

You can call the locateOnScreen('calc7key.png') function to get the screen coordinates. The return value is a 4-integer tuple: (left, top, width, height).

I got error:

checkNumber1 = resourceBlankLightTemp[1]

TypeError: 'Process' object does not support indexing

import pyautogui, time, os, logging, sys, random, copy
import multiprocessing as mp

BLANK_DARK = os.path.join('images', 'blankDark.png')
BLANK_LIGHT = os.path.join('images', 'blankLight.png')

def blankFirstDarkResourcesIconPosition():
    blankDarkIcon = pyautogui.locateOnScreen(BLANK_DARK)
    return blankDarkIcon


def blankFirstLightResourcesIconPosition():
    blankLightIcon = pyautogui.locateOnScreen(BLANK_LIGHT)
    return blankLightIcon


def getRegionOfResourceImage():

    global resourceIconRegion

    resourceBlankLightTemp = mp.Process(target = blankFirstLightResourcesIconPosition)
    resourceBlankDarkTemp = mp.Process(target = blankFirstDarkResourcesIconPosition)

    resourceBlankLightTemp.start()
    resourceBlankDarkTemp.start()

    if(resourceBlankLightTemp == None):
        checkNumber1 = 2000
    else:
        checkNumber1 = resourceBlankLightTemp[1]

    if(resourceBlankDarkTemp == None):
        checkNumber2 = 2000
    else:
        checkNumber2 = resourceBlankDarkTemp[1]
Drise
  • 4,310
  • 5
  • 41
  • 66
Irutar
  • 1
  • 2
  • https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process `mp.Process` returns a Process object, not an iterable. I think you're looking to use `Pipe`, but I'm not well versed in MP. – Drise Mar 29 '18 at 14:58
  • So the actual question is: How to get the result of a function call handled in a `Process`. Does [this](https://stackoverflow.com/q/30189270/1639625) help? – tobias_k Mar 29 '18 at 14:59
  • Possible duplicate of [How to access the result of a function called in a multiprocessing in Python?](https://stackoverflow.com/questions/27767206/how-to-access-the-result-of-a-function-called-in-a-multiprocessing-in-python) – Drise Mar 29 '18 at 15:00
  • @tobias_k Shockingly enough, there exists a question with almost that *exact* same title. – Drise Mar 29 '18 at 15:02

1 Answers1

0

In general, if you just want to use multiprocessing to run existing CPU-intensive functions in parallel, it is easiest to do through a Pool, as shown in the example at the beginning of the documentation:

# ...

def getRegionOfResourceImage():

    global resourceIconRegion

    with mp.Pool(2) as p:
        resourceBlankLightTemp, resourceBlankDarkTemp = p.map(
            lambda x: x(), [blankFirstLightResourcesIconPosition,
                            blankFirstDarkResourcesIconPosition])

    if(resourceBlankLightTemp == None):
        # ...
Drise
  • 4,310
  • 5
  • 41
  • 66
jdehesa
  • 58,456
  • 7
  • 77
  • 121