How to keep Console area fixed for a thread
Nikunj.Badjatya at emc.com
Nikunj.Badjatya at emc.com
Thu Nov 24 10:35:36 EST 2011
Hi All,
Please look at the code below.
I am using pypi progressbar. But in general, How can I keep the area of the console fixed for the thread to print its status on it.
{{{
import sys
import time
import threading
import os
from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \
FileTransferSpeed, FormatLabel, Percentage, \
ProgressBar, ReverseBar, RotatingMarker, \
SimpleProgress, Timer
def ProgBar():
widgets = [' ', Percentage(), ' ', Bar(marker='#',left='[',right=']'),' ']
pbar = ProgressBar(widgets=widgets, maxval=100)
pbar.start()
return pbar
def update2(i):
os.environ["PBAR"] = i
print("This will print for every call to update")
return
class MyThread(threading.Thread):
def run(self):
l = 0
while True:
n = os.getenv("PBAR", "")
if len(n) != 0:
n = int(n)
if n > l:
pbar.update(n)
l = n
if n == 100:
break
else:
continue
pbar = ProgBar()
mythread = MyThread()
mythread.daemon = True
mythread.start()
for i in range(101):
update2("{0}".format(i))
time.sleep(0.25)
}}}
{{{
Output:
[cid:image002.jpg at 01CCAAEC.CFE44870]
}}}
But I require the output to be of type:
{{{
13% [########### ]
This will print for every call to update
This will print for every call to update
This will print for every call to update
This will print for every call to update
This will print for every call to update
}}}
This is just a sample piece of code for narrowing down the problem.
How can I fix the cursor position fix for the thread which is updating my progressbar .?
Thanks
Nikunj
Bangalore-India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111124/7433360e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 37098 bytes
Desc: image002.jpg
URL: <http://mail.python.org/pipermail/python-list/attachments/20111124/7433360e/attachment.jpg>
More information about the Python-list
mailing list