用Future做并发

并发代码范例:

with ThreadPoolExecutor(c) as executor:
  res = executor.map(proc,para_list)

future对象有.done()方法非阻塞返回bool,.add_done_callback()添加回调,.result()返回结果

future.as_completed(future_iter)返回的future都可以无阻塞调用result。

GIL对阻塞性I/O无害

CPU密集型用ProcessPoolExecutor

Executor.map返回result generator

你可能感兴趣的:(用Future做并发)