TypeError:cpu_count()占用1个位置参数,但给出了2个

时间:2017-03-11 13:02:01

标签: python parallel-processing multiprocessing

我试图掌握多处理功能(我的Mac上有2个CPU)。我的代码大致如下:

def new_func(i):
    Rewards, Times, CummulativeRewards, Weights = Q_learning(model, variants = 2, stages = 3, gamma = 0.975, epsilon = 0.99, batchSize = i, buffer = 3000, randSeed = 42, replay = None)
    return CummulativeRewards

from joblib import Parallel, delayed import multiprocessing

BatchSize = [100, 300]
num_cores = multiprocessing.cpu_count(2)
Rewards, Times, CuRew, Weights = Parallel(n_jobs=num_cores)(delayed(new_func)(i) for i in BatchSize)

我收到以下错误: num_cores = multiprocessing.cpu_count(2) TypeError: cpu_count() takes 1 positional argument but 2 were given

任何想法是什么问题?

1 个答案:

答案 0 :(得分:2)

cpu_count不接受任何参数。一个位置参数是自我实例multiprocessing

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.cpu_count

num_cores = multiprocessing.cpu_count()