Reputation: 591
I have a master thread that spawns other threads. The master thread does periodic status checks that I print/flush/update with:
status = "Queued: {} | Workers: {}".format(queued_status, worker_status)
sys.stdout.flush()
sys.stdout.write("\r{}".format(status))
This works great, but it ultimately gets jumbled in with the print statements from the worker threads.
So, how would I designate the status print to the top (it just updates in place), and have the threads print below? Something like this:
Queued: No | Workers: 4
........................
Thread print
Thread print
Thread print
Where the thread print will just keep scrolling (like a normal terminal window), but the status is locked to the top.
Upvotes: 0
Views: 54
Reputation: 9597
The curses
module is the usual solution for printing to a particular place on the screen. You'd still need to arrange for all of the text to be printed from a single thread, to avoid near-simultaneous prints from getting jumbled together; this is typically done with a Queue.Queue
(workers add to the queue rather than printing directly; main thread pops from queue if non-empty and prints).
Upvotes: 2