使用多处理库运行python代码时出现问题

时间:2020-01-23 09:31:20

标签: python multithreading

我正在使用多处理程序包来并行化程序。 现在我在本教程上遇到了一个问题,代码如下:

def howmany_within_range(row, minimum, maximum):
  """Returns how many numbers lie within `maximum` and `minimum` in a given `row`"""
  count = 0
  for n in row:
    if minimum <= n <= maximum:
        count = count + 1
  return count    

np.random.RandomState(100)
arr = np.random.randint(0, 10, size=[200000, 5])
data = arr.tolist()

pool = mp.Pool(5)


results = [pool.apply(howmany_within_range, args=(row, 4, 8)) for row in data]


pool.close()    

print(results[:10])

我尝试与Anaconda一起运行,但程序卡住了,然后尝试在Qt控制台上运行,但出现此错误:模块' main '没有属性' spec ' 有运行该程序的方法吗?

0 个答案:

没有答案