Threads and Progress Bar

Thomas Guettler guettli at thomas-guettler.de
Fri Sep 15 09:49:00 EDT 2006


On Fri, 01 Sep 2006 21:43:46 +0530
Ritesh Raj Sarraf <rrs at researchut.com> wrote:

> Hi,
> 
> I have a small application, written in Python, that uses threads.
> The application uses function foo() to download files from the web. As it reads
> data from the web server, it runs a progress bar by calling an install of a
> progress bar class.
> 
> When using threads, I get the problem that the progress bar gets over-written by
> the download progress of files from other threads.
> 
> I believe my change has to go into the progress bar class to make it thread
> aware.

You need some kind of lock. Look at the module threading. There
is a class called "Lock".

PS: If you use pygtk: I switched from using threads to idle_add and (*). This is much easier
and you don't need any locking. 

# (*)
while gtk.events_pending():
   gtk.main_iteration()

-- 
Thomas Güttler, http://www.tbz-pariv.de/ 
Bernsdorfer Str. 210-212, 09126 Chemnitz, Tel.: 0371/5347-917



More information about the Python-list mailing list