Skip to content
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

file_upload demo: yield write() cb in body_producer #2149

Merged
merged 2 commits into from
Sep 23, 2017

Conversation

ploxiln
Copy link
Contributor

@ploxiln ploxiln commented Sep 8, 2017

The documentation for tornado.httpclient.HTTPRequest says:

body_producer – Callable used for lazy/asynchronous request bodies. It is called with one argument, a write function, and should return a Future. It should call the write function with new data as it becomes available. The write function returns a Future which can be used for flow control.

In the simpler example in this demo, raw_producer(), there are no yields (or awaits) at all. It doesn't make much sense to use a body_producer callback if it generates and writes the whole body all at once without ever yielding, you might as well have just generated the whole body up front. In the more complex example, multipart_producer(), it looks like yield gen.moment was thrown in to allow some of the body to be sent before more of the body is produced, but that seems less elegant than just yielding write().

It's possible I just don't understand the nuances, so consider this half-question half-proposal :)

Copy link
Member

@bdarnell bdarnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should be yielding the write futures. It could potentially make sense to use body_producer without yielding the write futures if generating the body is asynchronous (and is assumed to be slower than the network), but that's not the case here (and even if generating the body were slow there's no harm in also waiting for flow control).

@bdarnell bdarnell merged commit 1c2eb67 into tornadoweb:master Sep 23, 2017
@ploxiln ploxiln deleted the file_upload_yield branch April 11, 2018 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants