Cannot print the terminal output in Streamlit?

Hello @Charly_Wargnier,
So instead of appending the text, you want it to be overriden.

You could try something like this:

# Before
def new_write(b):
    if getattr(current_thread(), REPORT_CONTEXT_ATTR_NAME, None):
        buffer.write(b)
        output_func(buffer.getvalue())
    else:
        old_write(b)

# After
def new_write(b):
    if getattr(current_thread(), REPORT_CONTEXT_ATTR_NAME, None):
        buffer.write(b)
        output_func(b)  # Changed here
    else:
        old_write(b)
1 Like

Thanks Synode! I’ll have a proper look asap. :slight_smile:

Did you get a solution?

Hey Filip!

If you could send some kind of notification in a few hours when i will be near the PC, I will provied you with a solution I’ve managed to create using some of the code here, which works great, not exactly a console, but you are able to see the output if it’s comming from ‘logging’, and you can see it on the screen :slight_smile:

Best regards.

1 Like

This is my problem. I’m utilizing a library that prints this things in my Console output.

I would like to print the same messages in Streamlit page.

Can you help me?

Hello @BugzTheBunny ! I’m interested if you could provide a solution for the output coming from “logging” :slight_smile:

This code is great, thank you @okld for your work and @Charly_Wargnier for asking the question :slight_smile:

Have a nice day!

Hi guys, ive made a demo of the samples of the code here, you may view it in this repo:

@Ejoz @filipespacheco

1 Like

Thank you so much @BugzTheBunny, it works like a charm! (And I’m really sorry I haven’t seen your message sooner).

1 Like

Not a problem, glad it works and can be helpfull!

the codes is work, but mix the output into one line, so i add “\r\n” in the new_write(), just FYI.

    def new_write(b):
        if getattr(current_thread(), REPORT_CONTEXT_ATTR_NAME, None):
            buffer.write(b+"\r\n")
            output_func(buffer.getvalue())
        else:
            old_write(b)
1 Like

Is there a way to limit the number of lines that are printed?

I have an app that has a long running process with many steps. Each step prints to the console as part of its progress. I only want to display the last 10 lines of stderr. Is this possible?

Thanks in advance