screen output problem

R

Ritesh Raj Sarraf

Hi,

I have, for very long, been trying to find a consistent solution (which
could work across major python platforms - Linux, Windows, Mac OS X)
for the following problem.

I have a function which downloads files from the web. I've made the
function threaded. I'm trying to implement a progress bar for it which
could work across all the platforms.

The problem is that when the progress bar is displayed, all the threads
overwrite the progress bar.

I've thought of using curses but AFAIK curses is not available for
Windows.

Is there a generic way to accomplish the following:

progress = "[===================]\n[=======================]"
for x in range(5):
sys.stdout.write(progress + "\r")

Basically, I want a way through which I want to display data on two
lines and make sure that "\r" overwrites the two lines without putting
a newline making sure that whatever library it uses is available across
all major Python platforms.

Thanks,
Ritesh
 
C

Calvin Spealman

Hi,

I have, for very long, been trying to find a consistent solution (which
could work across major python platforms - Linux, Windows, Mac OS X)
for the following problem.

I have a function which downloads files from the web. I've made the
function threaded. I'm trying to implement a progress bar for it which
could work across all the platforms.

The problem is that when the progress bar is displayed, all the threads
overwrite the progress bar.

I've thought of using curses but AFAIK curses is not available for
Windows.

Is there a generic way to accomplish the following:

progress = "[===================]\n[=======================]"
for x in range(5):
sys.stdout.write(progress + "\r")

Basically, I want a way through which I want to display data on two
lines and make sure that "\r" overwrites the two lines without putting
a newline making sure that whatever library it uses is available across
all major Python platforms.

Thanks,
Ritesh

Take a look at this:
http://cheeseshop.python.org/pypi/progressbar
 
R

Ritesh Raj Sarraf


Hi,

Sorry for being a little late in replying.

The progressbar implementation is excellent but it has the same problems that
the current progressbar implementation I use, has.

In the above mentioned progressbar implementation also, the progressbar status
is overwritten if you're using multiple threads.

If your application is threaded, and multiple threads are downloading multiple
files, you get a progressbar which is overwritten by all the 3 threads.

I had brought this issue some time back too.
Dennis Lee Bieber had a solution which looked better but not very much. His
implementation had os.system(clear/cls) being called (to update the progress)
which made the screen flicker if your network latency was low (especially in
cases where the data is indirectly being downloaded from a Proxy or a product
like NetApp's Netcache).

If there's a way to print multiple lines of text withouth the newline ("\n")
character, we can then use carriage return ("\r") and implement a proper
progressbar with a bar for each separate progress action.

Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."
"Stealing logic from one person is plagiarism, stealing from many is
research."
"The great are those who achieve the impossible, the petty are those who
cannot - rrs"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQBFbAU94Rhi6gTxMLwRAh5NAJ0ZAkMF+ykF5OtDOKta3MztRKJWeACbB0LZ
cNEjxN1RqUWd4IOF+5QXHqo=
=8FBd
-----END PGP SIGNATURE-----
 
D

Dennis Lee Bieber

If there's a way to print multiple lines of text withouth the newline ("\n")
character, we can then use carriage return ("\r") and implement a proper
progressbar with a bar for each separate progress action.
If you were running on an Amiga, or via a serial port connection to
an old VT-100 terminal, it would be child's play... Since both
understood the same terminal control codes for moving the cursor around
a text display.

The old MS-DOS "ANSI" console driver may have understood that set.
But M$, in its great and all-powerful wisdom, seems to feel that the
only need for a command line interface is for batch configuration
scripts that run with no human interaction, and hence with no need for
status. One is expected to code a GUI instead if such things as
progress-bars are needed.

A google for "windows console cursor control" brings up (a bit of a
surprise since I my search terms didn't mention Python):

http://newcenturycomputers.net/projects/wconio.html

Of course, this isn't portable to LINUX or other operating systems...

Also, looking at win32api, I find a SetCursorPos() (and matching
get...).

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
R

Ritesh Raj Sarraf

I'm not sure if there is a definite solution to this problem.

I've noticed that one of the applications, which I use on a daily basis
(apt from Debian) does address the progress bar issue in another way.

When apt tries to download multiple files, it displays the progress of
all the downloads on a single line. Probably the apt developers also
might have run into the same issue and hence settled down with this
workaround.


Thanks,
Ritesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top