python-3.x - concurrent.futures.ProcessPoolExecutor() 的 Python : Get multiple return values and provide multiple arguments in executor. 映射

标签 python-3.x python-multiprocessing threadpoolexecutor

我对 Python 多处理概念还很陌生。 我正在尝试调用具有多个参数的函数 magicFunction,其中第一个参数是可迭代的,而所有其他参数都是不可迭代的。此外,它返回多个值,让我们说 x, y, z

我想弄清楚如何在这里使用 executor。这是我的方法,这显然是错误的。

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)

有人可以建议正确的方法吗?

最佳答案

你可以使用一个类:

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)

这将打印 1 2 3

关于python-3.x - concurrent.futures.ProcessPoolExecutor() 的 Python : Get multiple return values and provide multiple arguments in executor. 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54656526/

相关文章:

python-3.x - 提取几何(形状)内的数据

python - 配置返回代码 256 - python setup.py egg_info 失败,错误代码为 1 in/tmp/pip_build_root/lxml

python - 在列表中查找组合的更优雅的方法是什么?

python - 在 Python 的多处理库中获取队列的长度

java - ThreadPoolExecutor javadoc,排队和锁定的三种策略

java - 执行器的线程池计数是否会影响给定主任务的子任务?

python-3.x - python : only two decimal places after user entered number

python-3.x - 在 Python 多处理中共享文件描述符

Python 多处理 - 进程之间的管道通信

spring - 带有 ThreadPoolTask​​Executor 的 Spring 的默认队列大小是多少?