Thread Question

Carl Banks pavlovevidence at gmail.com
Fri Aug 4 07:29:02 EDT 2006


Ritesh Raj Sarraf wrote:
> Carl Banks wrote:
> > Then change the zipping part of download_from_web to acquire and
> > release this lock; do zipfile operations only between them.
> >
> > ziplock.acquire()
> > try:
> >     do_all_zipfile_stuff_here()
> > finally:
> >     ziplock.release()
>
> I hope while one thread has acquired the lock, the other threads (which
> have done the downloading work and are ready to zip) would wait.

Exactly.  Only one thread can hold a lock at a time.  If a thread tries
to acquire a lock that some other thread has, it'll wait until the
other thread releases it.  You need locks to do this stuff because most
things (such as zipfile objects) don't wait for other threads to
finish.


Carl Banks




More information about the Python-list mailing list