Skip to content

Commit 2306545

Browse files
Apply suggestions from code review
Co-authored-by: Ian Currie <[email protected]>
1 parent 555733f commit 2306545

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

flush-print/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The approach to calculate it is somewhat manual:
3434
- If they pause, remember the last number that got printed before the pause
3535
- If they don't pause, increase the value of `SLIGHTLY_TOO_LARGE_FOR_BUFFER` by `10_000` and start from the top
3636

37-
Continue doing this until your script paused when printing the numbers, and you noted the number that displayed last during the pause. Once you have that number, subtract it from the value that `SLIGHTLY_TOO_LARGE_FOR_BUFFER` currently has to calculate your buffer size estimation, for example:
37+
Continue doing this until your script paused when printing the numbers, and you noted the number that displayed last during the pause. Once you have that number, manually subtract it from the value that `SLIGHTLY_TOO_LARGE_FOR_BUFFER` currently has to calculate your buffer size estimation, for example:
3838

3939
```python
4040
SLIGHTLY_TOO_LARGE_FOR_BUFFER = 80_000
@@ -49,7 +49,9 @@ You can divide the number you get by `1000` to get an estimation of your buffer
4949

5050
If you want to, you could even drill down further with some manual binary search to find the exact byte when the break first occurs.
5151

52-
The idea of this script is that each of these printed numbers take up exactly 6 bytes in the buffer, which you assure with the format specifier in the f-string that you pass to `print()`. When the buffer gets filled up so much that it needs to flush during the execution of your script, then you run into the break in the printout, caused by the call to `time.sleep()` executing. Finally, when the script finishes execution after the break, Python flushes the rest of the buffer contents, which prints the remaining numbers to your terminal.
52+
The idea of this script is that each of these printed numbers take up exactly 6 bytes in the buffer. This is assuming that you're using an encoding in which numbers and spaces take up one byte. If so, then you can make sure each length is 6 characters with the format specifier in the f-string that you pass to `print()`.
53+
54+
At some point the buffer gets filled up so much that it needs to flush during the execution of your script. After it's flushed, it'll begin to fill up again. Ideally before it fills up again, you run into the call to `time.sleep()` executing. Finally, when the script finishes execution after the sleep, Python flushes the rest of the buffer contents, which prints the remaining numbers to your terminal.
5355

5456
Finally, you need to subtract from the current value of `SLIGHTLY_TOO_LARGE_FOR_BUFFER` because we assume that the buffer flushes continuously when it gets full, which means that whatever is in the buffer when the script is done should represent a full buffer.
5557

0 commit comments

Comments
 (0)