How to keep Console area fixed for a thread

Nikunj Badjatya nikunjbadjatya at gmail.com
Fri Nov 25 13:00:21 EST 2011


Can anyone throw some light on this please ! ?




On Thu, Nov 24, 2011 at 9:05 PM, <Nikunj.Badjatya at emc.com> wrote:

> 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:****
>
> ** **
>
> [image: output.jpeg]****
>
> ** **
>
> ** **
>
> }}}****
>
> ** **
>
> 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****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111125/31e24e00/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 37098 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20111125/31e24e00/attachment.jpg>


More information about the Python-list mailing list