concurrent.futures
https://docs.python.org/ja/3/library/concurrent.futures.html
Executor(抽象)
具象
ThreadPoolExecutor はスレッドのプールを使用して非同期に呼び出しを行う
ProcessPoolExecutor はプロセスプールを使って非同期呼び出しを実施する Executor のサブクラスです。
#multiprocessing モジュールを利用します。このため Global Interpreter Lock を回避することができますが、pickle 化できるオブジェクトしか実行したり返したりすることができません。
submitメソッド
呼び出し可能オブジェクト fn を、 fn(*args, **kwargs) として実行するようにスケジュールし、呼び出し可能オブジェクトの実行を表現する Future オブジェクトを返します。
『Python実践入門』では「先送り」
mapメソッドもある
ThreadPoolExecutor の例
ProcessPoolExecutor の例
Future クラスは呼び出し可能オブジェクトの非同期実行をカプセル化します。
モジュール関数
wait
Wait for the Future instances given by fs to complete.
as_completed
Returns an iterator over the Future instances given by fs that yields futures as they complete (finished or cancelled futures).
PEP 3148 – futures - execute computations asynchronously