Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Get multiple return values and provide multiple arguments in executor.map of concurrent.futures.ProcessPoolExecutor()

I am quite new to Python multiprocessing concept. I am trying to call function magicFunction which has multiple argument out of which first is iterable while all other are non-iterable. Also, it returns multiple value, let us say x, y, z

I am trying to figure out how to use executor here. Here is my approach, which is obviously wrong.

def magicFunction(webElem, uid_list, ignoreTagsList):
    ..
    ..
    return x,y,z

with concurrent.futures.ProcessPoolExecutor() as executor:
    for webElem, x_val, y_val, z_val in zip(webElem_list, executor.map(magicFunction, webElem_list, uid_list, ignoreTagsList)):
    ..
    ..
    print("Values:", x_val, y_val, z_val)

Can someone suggest correct way to do this ?

like image 973
Om Sao Avatar asked Dec 06 '25 18:12

Om Sao


1 Answers

You could use a class:

class FunctionReturn:
    x = 0
    y = 0
    z = 0

def myFunction():
    output = FunctionReturn()
    output.x = 1
    output.y = 2
    output.z = 3
    return output

data = myFunction()
print(data.x , data.y , data.z)

This will print 1 2 3

like image 176
C. Lang Avatar answered Dec 09 '25 14:12

C. Lang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!