Intermediate
Stop reading and close the stream
Write read_until_stop(stream, should_stop). stream is a generator of text pieces. Read pieces and join them into text. After adding each piece, call should_stop(text); when it returns True, stop reading.
Always close the generator before returning (so its cleanup code runs), whether you stopped early or read everything. Return the text.
What Check tests
- Reads everything when it never stops
- Stops as soon as should_stop is true
- The generator's cleanup runs after a stop
- The cleanup also runs when the stream finishes
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.