-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In submit_iteration, don't send None values to the future #236
Conversation
@@ -54,7 +54,13 @@ def __call__(self, send, cancelled): | |||
# exception carries that value. Return it. | |||
return e.value | |||
|
|||
send(GENERATED, result) | |||
# A plain yield without an argument should not send a message; it's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment needs to be rewritten, or possibly simply removed. The reference to yield
doesn't make sense in the case that what's been submitted is a simple iterator rather than a generator created by a generator function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could potentially simply point to the submit_iteration
function instead of repeating a portion/all of the docstring from that function here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Just to confirm, the final value of a future can be I can't think of a good reason why anyone would want the future to be |
Yes; this change doesn't affect the return value of the future (the
So it's true that the user can't ever send a This is a bit of an uneasy compromise. There are two distinct use-cases:
In the first case, it's the contents of the iterable that are of interest to the user. In the second case, it's the result that the user is after, and the yielded partial results are just icing on the cake. Possibly we actually want two separate job types. Let me rethink this one. |
Closing. This doesn't seem like the right way to go, partly because of the backwards compatibility break, partly because wanting to receive all values ( Instead, I think we want a new submission function |
The
submit_iteration
function provides a way to run a generator in the background, withyield
statements in that generator marking potential cancellation points.Currently, each
yield
statement also sends a message to the foreground future, making thoseyield
s somewhat heavyweight.This PR modifies the code so that:
yield
(or equivalently, ayield None
) marks a cancellation point, but does not send a value to the futureyield value
withvalue
non-None
both marks a cancellation point and sends a value to the futureThis is a significant change in user-visible behaviour. Technically it's backwards incompatible, but the likelihood of breakage seems small (and the fix for any such breakage should be very easy). Nevertheless, we need to advertise the change properly, so I've added a changelog entry to make sure that this doesn't get neglected at release time.
Closes #229.