Python 中使用多线程时,可以使用 Thread
类或 concurrent.futures
模块中的 ThreadPoolExecutor
类来创建线程。为了获取线程函数的返回值,可以使用 concurrent.futures
模块中的 Future
类。
使用 ThreadPoolExecutor
类创建线程时,可以通过调用 submit()
方法来提交线程函数,该方法会返回一个 Future
对象,可以使用该对象的 result()
方法来获取线程函数的返回值。
例如:
from concurrent.futures import Th