Carl Banks wrote: > If you have multiple threads trying to access the same ZIP file at the > same time, whether or not they use the same ZipFile object, you'll have > trouble. You'd have to change download_from_web to protect against > simultaneous use. A simple lock should suffice. Create the lock in > the main thread, like so: > > ziplock = threading.Lock() >
Thanks. This looks to be the correct way to go. I do have access to all the source code as it is under GPL. > 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. > If you can't change download_from_web, you might have no choice but to > download sequentially. > > OTOH, if each thread uses a different ZIP file (and a different ZipFile > object), you wouldn't have to use a lock. It doesn't sound like you're > doing that, though. > > It shouldn't be a problem if one thread is zipping at the same time > another is downloading, unless there's some common data between them > for some reason. > > Thanks, Ritesh -- http://mail.python.org/mailman/listinfo/python-list