def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
if self._broken:
raise BrokenThreadPool(self._broken)
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
if _shutdown:
raise RuntimeError('cannot schedule new futures after'
'interpreter shutdown')
f = _base.Future() #初始化一个future对象f
w = _WorkItem(f, fn, args, kwargs) #实际上是这个_WorkItem把(future对象,执行函数,函数需要的参数)放进去的,并且完成函数的执行,并且设置future的result
self._work_queue.put(w) #将w这个task放入 _work_queue队列,会在下面这个方法中,被起的Thread进行调用。
self._adjust_thread_count() #调整线程数量,并且初始化线程,开启线程。Thread方法的参数是self._work_queue。起来的线程中执行的task是上两步生成的w队列。
return f