question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FastIO output gets truncated in windows terminal

See original GitHub issue

Python Version: Python 3.7.7

Describe the bug Output gets truncated when printing a large amount of data over stdout (no problem with file I/O).

image

To Reproduce Copy FastIO.py from this repo to local, append these lines to the end of the file:

for x in range(5000):
    print(f"{x:0>7} Hello world!")

Expected behaviour It should print from 0000000 Hello world! to 0004999 Hello world!.

Additional context I change the lines above to this:

for x in range(5000):
    print(f"{x:0>7} Hello world!")
    if x % 1000 == 0:  # ofcoz, 1000 doesn't always work
        print(flush=True)

It works fine. This is error-prone. So I would like to ask whether it is possible to flush the output automatically whenever needed?

Thanks in advanced.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
bjorn-martinssoncommented, Dec 21, 2021

If I write like this:

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(open("test.txt", "w"))

it gives an error:

The reason why this fails is a stupid quirk with this specific implementation of FastIO. The problem is that since the file object is not stored anywhere, it gets garbage collected and is automatically closed. I told @cheran-senthil about this issue back when FastIO was added to pyrival, but he didn’t bother fixing it/ didn’t think it mattered. The fix is easy, just store the file object somewhere

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
0reactions
jaredliwcommented, Dec 21, 2021

If I write like this:

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(open("test.txt", "w"))

it gives an error:

Exception ignored in: <__main__.IOWrapper object at 0x00000165229EBBC8>
Traceback (most recent call last):
  File "test.py", line 41, in flush
    write(self._fd, self.buffer.getvalue())
OSError: [Errno 9] Bad file descriptor

is it as expected?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell truncates my output, how do I make it NEVER do ...
When this happens, it collapses extra content into a "..." so everything fits in the width of the console. Here's an example with...
Read more >
Output from WSL command pipeline is randomly truncated
The output is truncated? One of the programs in the pipeline is aborted early? It might be a timing issue? Repeating the last...
Read more >
Powershell cmd /c Output Truncated - TechNet - Microsoft
I'm pulling output from the command below into an array, bit it's being truncated at 20 items ( or 863 characters if i...
Read more >
See Everything In The Terminal/Command Prompt After Long ...
Inside your Terminal Window, go to Edit | Profile Preferences , click on the Scrolling tab, and check the Unlimited checkbox underneath the ......
Read more >
Terminal output truncated to 80 symbols : IDEA-117552
Output in "Terminal" window is truncated to 80 characters. Attachments 1 ... I get this when running cygwin bash.exe from IntelliJ Terminal window....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found