同时启动带有参数的3个不同的函数

问题描述 投票:0回答:1

我想在具有多核的机器上同时启动3个不同的功能。每个函数使用相同的模块(cx_Oracle)启动广泛的数据查询以分离数据库,并且每个函数都带有一些参数来调用。如何做到这一点?

我已经阅读了一些有关使用Python进行并行计算的内容,但是ProcessPoolExecutor总是返回BrokenProcessPool错误。脚本已保存(在其他SE项目中报告为问题)。

if __name__ == '__main__'
    with ProcessPoolExecutor(3) as executor:
        future_1 = executor.submit(query_1, arg1)
        future_2 = executor.submit(query_2, arg2)
        future_3 = executor.submit(query_3, arg3)
    result_1 = future_1.result()
    result_2 = future_2.result()
    result_3 = future_3.result()

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

您看过类似的东西吗?对其他线程的引用或带有参数的三个不同调用的示例对我来说就足够了。我也尝试过多处理,但没有成功。

python parallel-processing arguments cx-oracle
1个回答
0
投票

cx_Oracle示例Threads.py显示了在不同线程中运行两个语句:

. . .
def TheLongQuery():
     . . .

def DoALock():
    . . .


thread1 = threading.Thread(None, TheLongQuery)
thread1.start()

thread2 = threading.Thread(None, DoALock)
thread2.start()

thread1.join()
thread2.join()
© www.soinside.com 2019 - 2024. All rights reserved.