Replies: 2 comments 3 replies
-
|
Without thinking this through fully, I think I like 3 the most. If one use generators for streaming a huge page, it would be nice to avoid unnecessary memory allocations. I think that either you really want one-off generators or you do not. If you get a clear exception if you accidentally reuse them you can a) avoid rendering twice or b) wrap your generator in |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
I opened an issue for this: #102 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, there, @pelme and other htpythonistas!
I'm unsure if this should be considered a bug, intended behavior, or just a natural unavoidable consequence of generators being exhaustible, but I wanted to bring up a htpy rendering bug that took us a while to understand today. An htpy element had a child that was expressed as a generator, and the element was rendered twice, once for logging purposes (as a small isolated fragment) and once for rendering as part of the full-DOM response. The problem was that the second render did not contain the children, as the generator had been exhausted by the first render.
Here is a piece of simplified code that exemplifies this issue:
This is a consequence of the generator being exhausted, but I wonder if htpy wants to remove this foot gun in some way? Here are some different suggestions to start the discussion:
I have ordered my suggestions in my order of preference, but I'm interested in hearing what you have to say! Suggestion no. 1. has a memory cost, but in most, if not all, cases it is going to be negligible, I think.
Beta Was this translation helpful? Give feedback.
All reactions