Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.067 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'acquired': 0.04; 'blocked': 0.09; 'threads.': 0.09; 'cc:addr:python-list': 0.10; 'file,': 0.15; 'file.read()': 0.16; 'meanwhile': 0.16; 'subject:failed': 0.16; 'threads': 0.16; 'solution.': 0.18; 'cc:2**0': 0.23; 'example': 0.23; 'needed.': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'guess': 0.27; 'objects': 0.29; 'probably': 0.29; "i'm": 0.29; 'related': 0.30; 'becomes': 0.30; 'file': 0.32; 'right?': 0.33; 'problem': 0.33; 'open': 0.35; 'received:192.168.0': 0.35; 'but': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'possible.': 0.38; 'sure': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'your': 0.60; 'share': 0.61; 'received:62': 0.62; 'solve': 0.62; 'between': 0.63; 'more': 0.63; 'fin': 0.84; 'received:192.168.0.101': 0.84; 'received:192.168.13': 0.84; 'received:62.179': 0.84; 'received:62.179.121': 0.84; 'received:upcmail.net': 0.84 X-SourceIP: 89.134.225.226 Date: Wed, 01 Aug 2012 19:57:19 +0200 From: Laszlo Nagy User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: andrea crotti Subject: Re: CRC-checksum failed in gzip References: <50190ED6.1040100@shopzeus.com> <501956a7$0$29978$c3e8da3$5496439d@news.astraweb.com> <501961C7.1050405@shopzeus.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343843853 news.xs4all.nl 6945 [2001:888:2000:d::a6]:57035 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26375 >> Make sure that file objects are not shared between threads. If that is >> possible. It will probably solve the problem (if that is related to >> threads). > > Well I just have to create a lock I guess right? That is also a solution. You need to call file.read() inside an acquired lock. > with lock: > # open file > # read content > But not that way! Your example will keep the lock acquired for the lifetime of the file, so it cannot be shared between threads. More likely: ## Open file lock = threading.Lock() fin = gzip.open(file_path...) # Now you can share the file object between threads. # and do this inside any thread: ## data needed. block until the file object becomes usable. with lock: data = fin.read(....) # other threads are blocked while I'm reading ## use your data here, meanwhile other threads can read