multiple screens using python -
i have python script running 2 big processes, when run them both triggered , produce output in same stdout. looking , want print them in different stdout(probably process1 in screen1 , prrocess2 in screen2)
#main.py def proc1(): #do def proc2(): #do p1 = threading.thread(target=proc1) p2 = threading.thread(target=proc2) p1.start() p2.start() what required p1 should run in 1 screen , p2 should run in screen viewing running log,easy understanding , debugging. possible??
if can't change print output, , must stdout, it's not possible, because stream queued in stdout buffer in interleaving way, , there's no way distinguish text comes stream.
if want see output in real-time 2 different streams on different screens, can write second output (or both on different files) on file, output2.txt, on terminal, live read file using tail -f.
from man page:
the -f option causes tail not stop when end of file reached, rather wait additional data appended input. -f option ignored if standard input pipe, not if fifo.
so, assuming write 2 outstreams 2 different file, output1.txt , output2.txt, can run script in following manner:
screen 1:
python script.py screen 2 (for seeing output thread 1):
tail -f output1.txt screen 3 (for seeing output thread 2):
tail -f output2.txt or, if prefer 2 active screens @ time, can output first thread output stdout.
p.s.: you're not having 2 processes, rather, 2 threads. 2 different things, don't mix them up.
Comments
Post a Comment