Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Mod : Example 16-17 grouper optimization#5

Open
lbbc1117 wants to merge1 commit intofluentpython:master
base:master
Choose a base branch
Loading
fromlbbc1117:master

Conversation

lbbc1117
Copy link

@lbbc1117lbbc1117 commentedMay 14, 2017
edited
Loading

The delegating generator grouper delegates averager inside a while loop.
Every time averager returns, a new but useless averager instance will be created during the following loop period.
Adding ayield statement afteryield from averager() without while loop would be better.
Great great book, by the way.

yuanji-dev and austinbravo reacted with thumbs up emoji
@austinbravo
Copy link

austinbravo commentedFeb 19, 2020
edited
Loading

@ramalho i think the example should be this. currently, a new delegating generator is created for each item indata, which makes grouper's while loop unnecessary and creates the unused averager instance. grouper is also still active when the results are reported, though not sure if this matters as will be garbage collected once main() returns.

def grouper(results):    while True:        key = yield        results[key] = yield from averager()def main(data):    results = {}    group = grouper(results)    next(group)    for key, values in data.items():        group.send(key)        for value in values:            group.send(value)        group.send(None)    group.close() # just to highlight that grouper is still an active generator    report(results)

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@lbbc1117@austinbravo

[8]ページ先頭

©2009-2025 Movatter.jp