From 814cd3f4d8dd6a11d7be14a560db0115c7926435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bill=26=E5=B0=8F=E8=83=96?= Date: Sun, 14 May 2017 20:15:28 +0800 Subject: [PATCH] Example 16-17 grouper optimization --- 16-coroutine/coroaverager3.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/16-coroutine/coroaverager3.py b/16-coroutine/coroaverager3.py index c89a3fd..32492bb 100644 --- a/16-coroutine/coroaverager3.py +++ b/16-coroutine/coroaverager3.py @@ -63,8 +63,11 @@ def averager(): # <1> # the delegating generator def grouper(results, key): # <5> - while True: # <6> - results[key] = yield from averager() # <7> + # while True: # <6> + results[key] = yield from averager() # <7> + # When group.send(None) is called, group runs to the yield statement below + # without raising StopIteration and creating a useless new instance of averager + yield # the client code, a.k.a. the caller