CRC-checksum failed in gzip

andrea crotti andrea.crotti.0 at gmail.com
Thu Aug 2 06:59:28 EDT 2012


2012/8/2 andrea crotti <andrea.crotti.0 at gmail.com>:
>
> Ok sure that makes sense, but then this explanation is maybe not right
> anymore, because I'm quite sure that the file object is *not* shared
> between threads, everything happens inside a thread..
>
> I managed to get some errors doing this with a big file
> class OpenAndRead(threading.Thread):
>      def run(self):
>          global fz
>          fz.read(100)
>
> if __name__ == '__main__':
>
>     fz = gzip.open('bigfile.avi.gz')
>     for i in range(20):
>          OpenAndRead().start()
>
> and it doesn't fail without the *global*, but this is definitively not
> what the code does, because every thread gets a new file object, it's
> not shared..
>
> Anyway we'll read once for all the threads or add the lock, and
> hopefully it should solve the problem, even if I'm not convinced yet
> that it was this.


Just for completeness as suggested this also does not fail:

class OpenAndRead(threading.Thread):
    def __init__(self, lock):
        threading.Thread.__init__(self)
        self.lock = lock

    def run(self):
         global fz
         with self.lock:
             fz.read(100)

if __name__ == '__main__':
    lock = threading.Lock()
    fz = gzip.open('bigfile.avi.gz')
    for i in range(20):
         OpenAndRead(lock).start()



More information about the Python-list mailing list