apowers313
apowers313•8h ago

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:
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()
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)
3 Replies
Hall
Hall•8h ago
Someone will reply to you shortly. In the meantime, this might help:
apowers313
apowers313OP•8h ago
GitHub
Thread-local runtime context makes I/O methods not work in notebook...
Describe the bug The runtime context is a threadlocal, which was convenient for us when running marimo notebooks as apps (each session runs in its own thread). This however means that I/O doesn&#39...
apowers313
apowers313OP•8h ago
apparently the AI is better at finding related issues than I am 😉 I take it back, even mo.Thread doesn't capture the output

Did you find this page helpful?