最終更新:2021-08-14 (土) 08:53:52 (986d)
Python/await
コルーチンが実行を返すのを待ち、実行が終わるまで制御を解放してイベントループに渡す
passes function control back to the event loop. (It suspends the execution of the surrounding coroutine.)
- futureのcompleteを待つ
Python/awaitableオブジェクト
- await 文に指定できるオブジェクト
- awaitable オブジェクトには主に3つの種類があります:
Python/コルーチンオブジェクト?
- 他のコルーチンを待機させられる
Python/Task
- コルーチンを 並行に スケジュールするのに使う
- コルーチンが Task にラップされているとき、自動的にコルーチンは即時実行されるようにスケジュールされる
Python/Future
動作
Python/await {future}
- その時点で一旦停止し、完了したら続きを実行
- 制御を手放す
- suspends the coroutine until the future is done, then returns the future's result, or raises an exception, which will be propagated.
- 引数
- asyncio.Task
- loop.create_task(coro)
- asyncio.create_task(coro)
- asyncio.Task
Python/await {coroutine}
- コルーチンの完了を待機
- wait for another <coroutine> to produce a result (or raise an exception, which will be propagated).
メモ
- await文が未完了なFutureを受け取ると、そのコルーチンをブロックし、別の実行可能なコルーチンを実行します。
- 途中でFutureのステータスが完了に移行すると、ブロックが解除され コルーチンが再開します。