Print() immediately?

Is it possibly to get a print() show up in the textport immediately and not at the end of the script ? or frame ? (not sure how it actually behaves)

print("a")
time.sleep(3)

will currently print “a” after sleeping

AFAIK, TouchDesigner will wait for your frame to be processed and will freeze while sleeping.
That’s why you won’t see b be printed after 3 seconds.

asyncio module can help you achieve what you are looking for, and someone here already tried to use it inside TouchDesigner : Using asyncio module in TouchDesigner

I know, maybe I wasnt totally clear (I just edited above question)

The question is if there is a way to get ‚A“ printed (and the textport refreshed) before the actual sleeping (or any blocking operation ) starts.

I got your question right, no worries.

I tried flushing the output using print('a', flush=True) and sys.stdout.flush() without success.
I guess that’s not possible, maybe someone from TD can be of better help.

there is ui.refresh() and from the sound of it it seems lke the right fit, but sadly, even that is not doing it.
I suppose that print is put onto a stack and only displayed when the frame renders after everything is calculated instead of calling the draw-routine every time something is printed (which would cost even more performance)…