python - Non-interfering printing from threads -
doing threading python script , spits out stuff in kinds of orders. however, want print out single "remaining: x" @ end of each thread , erase line before next print statement. basically, i'm trying implement progress/status update erases before next print statement.
i have this:
for in range(1,10): print "something here" print "remaining: x" sleep(5) sys.stdout.write("\033[f") sys.stdout.write("\033[k")
this works fine when you're printing out way is; however, implement threading, "remaining" text doesn't wiped out time , "something here" right before wipes out previous line.
just need bit of trying figure out best way progress/status text organized multithreading.
thanks.
since code doesn't include threads it's difficult give specific advice doing wrong.
if it's output sequencing bothers you, however, should learn locking, , have threads share lock. idea grab lock (so nobody else can), send output , flush stream before releasing lock.
however, way code structured makes difficult, since there no way guarantee cursor end @ specific position when have multiple threads writing output.
Comments
Post a Comment