Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '__name__': 0.07; 'created,': 0.09; 'threads.': 0.09; 'throw': 0.09; 'def': 0.10; 'thread': 0.11; "'__main__':": 0.16; 'reproduce': 0.16; 'run(self):': 0.16; 'subject:failed': 0.16; 'threading': 0.16; 'threads': 0.16; 'fix': 0.17; 'file.': 0.20; 'import': 0.21; 'example': 0.23; 'to:2**1': 0.23; 'idea': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'start,': 0.27; 'run': 0.28; 'class': 0.29; 'code': 0.31; 'file': 0.32; 'not.': 0.32; 'could': 0.32; 'right?': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'help': 0.40; 'your': 0.60; 'matter': 0.61; 'share': 0.61; 'between': 0.63; 'here': 0.65; 'started.': 0.65; 'received:204': 0.72; 'fl:': 0.84; 'happening?': 0.84 Date: Thu, 02 Aug 2012 12:21:24 +0200 From: Laszlo Nagy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: andrea crotti , python-list@python.org Subject: Re: CRC-checksum failed in gzip References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343902890 news.xs4all.nl 6948 [2001:888:2000:d::a6]:45914 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26395 > One last thing I would like to do before I add this fix is to actually > be able to reproduce this behaviour, and I thought I could just do the > following: > > import gzip > import threading > > > class OpenAndRead(threading.Thread): > def run(self): > fz = gzip.open('out2.txt.gz') > fz.read() > fz.close() > > > if __name__ == '__main__': > for i in range(100): > OpenAndRead().start() > > > But no matter how many threads I start, I can't reproduce the CRC > error, any idea how I can try to help it happening? Your example did not share the file object between threads. Here an example that does that: class OpenAndRead(threading.Thread): def run(self): global fz fz.read(100) if __name__ == '__main__': fz = gzip.open('out2.txt.gz') for i in range(10): OpenAndRead().start() Try this with a huge file. And here is the one that should never throw CRC error, because the file object is protected by a lock: class OpenAndRead(threading.Thread): def run(self): global fz global fl with fl: fz.read(100) if __name__ == '__main__': fz = gzip.open('out2.txt.gz') fl = threading.Lock() for i in range(2): OpenAndRead().start() > > The code in run should be shared by all the threads since there are no > locks, right? The code is shared but the file object is not. In your example, a new file object is created, every time a thread is started.