单独调用其他模块中函数正常
多线程调用时显示
other.py中:
def f(x):
return x*x
main.py中
import other
import multiprocessing
def go():
pool = multiprocessing.Pool(processes=4)
print pool.map(f, range(10))
if __name__== '__main__' :
go()
显示错误:
AttributeError: '***' object has no attribute 'go'
解决办法:
import multiprocessing
pool = multiprocessing.Pool(processes=4)
替换成:
import pathos.pools as pp
pool = pp.ThreadPool(processes=4)
同样的,在linux环境中执行
with Pool(pool_num) as pool:
提示:
PermissionError: [Errno 13] Permission denied
修改为:
import pathos.pools as pp
with pp.ThreadPool(processes=pool_num) as pool: