我使用 Concurrent.Futures 模块创建了一个 ThreadPool。
我创建了线程,一切正常。
但现在我有一个函数,我想让它与线程并行,
问题是我需要每个线程应该运行的函数的返回值,并且不确定在使用 future 线程池模块时如何获取它。
有办法吗?
最佳答案
您对 result()
的理解是绝对错误的。来自 doc :
result(timeout=None)
Return the value returned by the call. If the call hasn’t yet completed then this method will wait up to timeout seconds. If the call hasn’t completed in timeout seconds, then a TimeoutError will be raised. timeout can be an int or float. If timeout is not specified or None, there is no limit to the wait time.If the future is cancelled before completing then CancelledError will be raised.
很明显
result()
将为您提供您提交的该功能的结果。
关于使用 Concurrent.Futures 模块作为 ThreadPool 调用 Python-get 函数的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224933/