Get result from multiprocessing process

2024/9/20 11:55:44

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 mpBLANK_DARK = os.path.join('images', 'blankDark.png')
BLANK_LIGHT = os.path.join('images', 'blankLight.png')def blankFirstDarkResourcesIconPosition():blankDarkIcon = pyautogui.locateOnScreen(BLANK_DARK)return blankDarkIcondef blankFirstLightResourcesIconPosition():blankLightIcon = pyautogui.locateOnScreen(BLANK_LIGHT)return blankLightIcondef getRegionOfResourceImage():global resourceIconRegionresourceBlankLightTemp = mp.Process(target = blankFirstLightResourcesIconPosition)resourceBlankDarkTemp = mp.Process(target = blankFirstDarkResourcesIconPosition)resourceBlankLightTemp.start()resourceBlankDarkTemp.start()if(resourceBlankLightTemp == None):checkNumber1 = 2000else:checkNumber1 = resourceBlankLightTemp[1]if(resourceBlankDarkTemp == None):checkNumber2 = 2000else:checkNumber2 = resourceBlankDarkTemp[1]
Answer

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 resourceIconRegionwith mp.Pool(2) as p:resourceBlankLightTemp, resourceBlankDarkTemp = p.map(lambda x: x(), [blankFirstLightResourcesIconPosition,blankFirstDarkResourcesIconPosition])if(resourceBlankLightTemp == None):# ...
https://en.xdnf.cn/q/119337.html

Related Q&A

How to do a second interpolation in python

I did my first interpolation with numpy.polyfit() and numpy.polyval() for 50 longitude values for a full satellite orbit.Now, I just want to look at a window of 0-4.5 degrees longitude and do a second …

How can I filter an ms-access databse, using QSqlTableModel and QLineEdit?

Im building a GUI that allows users to search information in a ms access database (yup. It has to be the ms access) The user has a textfield where he can type his search and the Tableview should update…

Python regex - Replace single quotes and brackets

Id like to replace quantities with name then a square bracket and a single quote with the contents inside. So, from this: RSQ(name[BAKD DK], name[A DKJ])to this:RSQ(BAKD DK, A DKJ)

Python unexpected EOF while parsing (python2.7)

Heres my python code. Could someone show me whats wrong with it? I try to learn an algorithm on solving 24 - point game. But I really dont know why this program has an error.from __future__ import div…

Call a function in repl without brackets

Would like to know if there is a way to call a function in python in repl just with the function name. $ python -i interace.py >>> load 834.png >>> sharpen >>> saverather tha…

how to work on a exist session in selenium with python?

I want to fill some field of a webpage and then send a request to it but this website has a very powerful login page to avoid sending requests for login from a robot so I cant log in with selenium bu…

how to find similarity between many strings and plot it

I have a xls file with one column and 10000 strings I want to do few things 1- make a heatmap or a cluster figure shows the similarity percentage between each string with another one.In order to find …

Python and Variable Scope

So I am recently new to Python, but I seem to be able to program some stuff and get it working. However Ive been trying to expand my knowledge of how things work in the language, and putting this simp…

How to check if element is orthogonally adjacent (next to) to existing elements?

Im trying to make a simple game where a building placed in a nested list must be next to another building. The problem I face is that if the building was placed at the sides, I cant use for loops to ch…

How to add new column(header) to a csv file from command line arguments

The output of the following code:-import datetime import csv file_name=sample.txt with open(file_name,rb) as f: reader = csv.reader(f,delimiter=",") …