Get help from the marimo community

Updated last week

Controlling output of long-running process?

My code creates a long-running thread in the background and I'd like to have all the output of the thread go to a single cell. Currently just the first message goes to the cell. Demo code:

Plain Text
 python
from threading import Thread
import time

def long_running():
    print("Thread starting:")
    i = 0
    while True:
        print(f"Loop {i}...")
        i += 1
        time.sleep(1)
    print("Thread exiting.")

t = Thread(target=long_running)
t.start()


Is there any way to capture the output from my thread in a specific cell?

(side note: this code also seems to cause auto export to raise an exception)
a
A
12 comments
apparently the AI is better at finding related issues than I am πŸ˜‰
I take it back, even mo.Thread doesn't capture the output
I really want to use marimo, but I think I'm stuck on how to get output from a thread... is there any work around? or thoughts on best practices of how to work with long running tasks in marimo?
turns out that this is a bug that's related to the sleep() statement in the thread: https://github.com/marimo-team/marimo/issues/3532
I forked marimo and started seeing if I could put together a pull request, but it's not clear to me how / why the print statements would end up in the console instead of the cell... the thread still has the KernelRuntimeContext associated with it and it still has the same Stdout object
there is this console_output_worker that has some timing loop associated with it, but it's not clear to me why it would print to console instead of just dropping the outputs: https://github.com/marimo-team/marimo/blob/01c1745634ede31b419e70ef484d34e128192033/marimo/_messaging/console_output_worker.py
Thanks for opening the issue and poking around. I'm not sure why this would happen, but it's certainly a bug. I can take a look
I know you're busy and I sincerely appreciate marimo, so I'm happy to do the work and free up some of your time if you can get me pointed in the right direction πŸ™‚
Thanks, means a lot! Here are a couple of pointers:

thx, I think I get it... I'll take a shot at a fix this afternoon
thanks again, I think I figured out a solution (see the GitHub issue) but I have to admit that there may be nuances of the state machine that I don't understand
Add a reply
Sign up and join the conversation on Discord