Skip to content

Commit f2948ad

Browse files
authored
README LE
1 parent 63259fa commit f2948ad

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

flush-print/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You don't need to install anything apart from a Python interpreter >=3.6 to run
88

99
## Countdown Script Variations
1010

11-
You can find all the code snippets that you've seen in the tutorial. For convenience, they're provided as separate files that all start with `countdown` and describe their differences with the rest of the file name. You can run each of the files separately without needing to edit the code, to see all the examples shown in the tutorial. Please visit the tutorial link for additional context.
11+
You can find all the code snippets that you've seen in the tutorial. For convenience, they're provided as separate files that all start with `countdown` and describe their differences with the rest of the filename. To see all the examples shown in the tutorial, you can run each of the files separately without needing to edit the code. Please visit the tutorial link for additional context.
1212

1313
## Terminal Based Visual Progress Indicators
1414

@@ -17,24 +17,24 @@ Additionally, this directory also contains two scripts that show example impleme
1717
- [`spinner.py`](spinner.py)
1818
- [`progress.py`](progress.py)
1919

20-
Both of them utilize explicit flushing and you can learn more about how to build them in [Your Guide to the Python `print()` Function](https://realpython.com/python-print/).
20+
Both of them utilize explicit flushing, and you can learn more about how to build them in [Your Guide to the Python `print()` Function](https://realpython.com/python-print/).
2121

2222
## Buffer Size Approximations
2323

2424
Finally, if you're curious to dive somewhat deeper into the rabbit hole of buffering in Python, you can take a look at [`buffersize.py`](buffersize.py).
2525

26-
There doesn't seem to be a way to get the size of the default buffer for stdout on your operating system directly through a Python object. If you know or find a way, please [contact the author](#about-the-author), I'd be very curious to know :)
26+
There doesn't seem to be a way to get the size of the default buffer for stdout on your operating system directly through a Python object. If you know or find a way, please [contact the author](#about-the-author). I'd be very curious to know :)
2727

28-
This script gives you a way to approximate the buffer size that Python uses when writing to stdout on your operating system and configuration. Note that this can be quite different between different setups.
28+
This script gives you a way to approximate the buffer size that Python uses when writing to stdout on your operating system and configuration. Note that this can be quite different across different setups.
2929

3030
The approach to calculate it is somewhat manual:
3131

32-
1. Run the script
33-
1. Note if the numbers that it prints pause in between before the script finishes execution
34-
- If they pause, remember the last number that got printed before the pause
35-
- If they don't pause, increase the value of `SLIGHTLY_TOO_LARGE_FOR_BUFFER` by `10_000` and start from the top
32+
1. Run the script.
33+
2. Note if the numbers that it prints pause in between before the script finishes execution.
34+
- If they pause, remember the last number that got printed before the pause.
35+
- 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, manually 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 pauses when printing the numbers, and note the number that displays 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
@@ -45,13 +45,13 @@ bufsize = 80_000 - 10919
4545
print(bufsize) # 69081 <-- Your buffer size approximation
4646
```
4747

48-
You can divide the number you get by `1000` to get an estimation of your buffer size for stdout in Kilobytes. In the example above, on a macOS system with a M1 chip, the buffer size of stdout when interacting with it through Python's `print()` would therefore be approximately 69 Kilobytes.
48+
You can divide the number you get by `1000` to get an estimation of your buffer size for stdout in kilobytes. In the example above, on a macOS system with a M1 chip, the buffer size of stdout when interacting with it through Python's `print()` would therefore be approximately 69 kilobytes.
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

5252
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()`.
5353

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.
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.
5555

5656
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.
5757

0 commit comments

Comments
 (0)