By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

screen output problem

P: n/a
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

Nov 25 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 25 Nov 2006 15:27:26 -0800, Ritesh Raj Sarraf <rr*@researchut.comwrote:
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

--
http://mail.python.org/mailman/listinfo/python-list
Take a look at this:
http://cheeseshop.python.org/pypi/progressbar

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Nov 26 '06 #2

P: n/a
On Sunday 26 November 2006 13:07, Calvin Spealman wrote:
Take a look at this:
http://cheeseshop.python.org/pypi/progressbar
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+ykF5OtDOKta3M ztRKJWeACbB0LZ
cNEjxN1RqUWd4IOF+5QXHqo=
=8FBd
-----END PGP SIGNATURE-----

Nov 28 '06 #3

P: n/a
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
Dennis Lee Bieber wrote:
On Tue, 28 Nov 2006 15:15:28 +0530, Ritesh Raj Sarraf
<rr*@researchut.comdeclaimed the following in comp.lang.python:

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
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Nov 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.