多线程进程
p = ThreadPool(processes=10) # creates a pool of 10 workers
p.map(function_to_call, iterable) # calls FUNCTION_TO_CALL with the first item from iterable as parameter
p.close() # closes the multi-threaded processes one all threads done
我一直在尝试使用这个模型,但是如果我想线程化一个没有参数的函数怎么办。像 run() 。我会为“可迭代”空间放什么,我一直在四处寻找,但找不到解决方案。
最佳答案
Pool.apply
功能就是你要找的。使用 Pool.apply_async
如果你想要一个非阻塞调用。
p = ThreadPool(processes=10)
p.apply(function_to_call)
p.close()
关于Python MultiProcessing.Pool : How to use with no iterable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43565035/