我想在Python中使用ProcessPoolExecutor,并为该函数提供一个常量参数和一个可迭代的参数。作为错误消息,我收到“ AttributeError:无法使本地对象'main ..'腌制”。如果我能使该功能正常工作,那就太好了!
import concurrent.futures
PRIMES = ['a','b','c']
def is_prime(_a, n):
return (_a, n)
def main():
a = '3'
with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor:
for result in executor.map(lambda x,y: is_prime(a,y), a, PRIMES):
print('is prime: %s' %result[0])
if __name__ == '__main__':
main()
谢谢!