N
N
Name_Zagotovka2020-10-11 17:46:02
Python
Name_Zagotovka, 2020-10-11 17:46:02

How to make parallel execution of python3 functions?

I use PyAutoGUI to search for an image on the screen, depending on the success / failure of the search. actions are performed.
At the moment I have about a dozen check format functions:

def chek_1(): 
        if pyautogui.locateOnScreen('img1.png',confidence=0.9):
            stat=0
        else:
            stat=1
        return(stat)

and actions (do) like this one:
def do1():
    pyautogui.press('f1')

the rest of the functions are of the same nature ...
and currently implemented in the following way
while True:
  if chek1()==1:
    do1()
  elif chek1()==0 and chek2()==1:
    do2()
  elif chek1()==1 and chek2()==0:
    do(10)

However, the processing speed is not as high as we would like...
Maybe the people involved have thoughts...how to make all the check*() functions be executed in parallel with the do functions. Those. so that the check functions would work, and return their results constantly, non-stop.
PS of various series of articles talk about the use of multiprocessing\streams to solve similar ones. however, the extremely low level of knowledge in python does not allow me to learn how it works...
if you write an example, I will be immensely grateful...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question