Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'puts': 0.07; 'rename': 0.07; 'subject:file': 0.07; 'try:': 0.07; 'subject:How': 0.09; 'blocking': 0.09; 'e.errno': 0.09; 'os.name': 0.09; 'def': 0.10; 'suggest': 0.11; 'file,': 0.15; 'b):': 0.16; 'operation.': 0.16; 'renames': 0.16; 'suppport': 0.16; 'termination.': 0.16; 'windows': 0.19; 'file.': 0.20; 'exists.': 0.22; 'to:2**1': 0.23; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.28; 'case,': 0.29; 'code': 0.31; 'implement': 0.32; 'file': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:192.168.0': 0.35; 'there': 0.35; 'except': 0.36; 'but': 0.36; 'enough': 0.36; 'does': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'side': 0.61; 'received:62': 0.62; 'between': 0.63; 'abnormal': 0.84; 'received:192.168.0.101': 0.84; 'received:192.168.13': 0.84; 'received:192.168.13.238': 0.84; 'received:62.179': 0.84; 'received:62.179.121': 0.84; 'received:edge03.upcmail.net': 0.84; 'received:upcmail.net': 0.84; 'subject:status': 0.84 X-SourceIP: 89.134.225.226 Date: Thu, 12 Jul 2012 19:46:17 +0200 From: Laszlo Nagy User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Plumo , python-list@python.org Subject: Re: How to safely maintain a status file References: 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342116183 news.xs4all.nl 6974 [2001:888:2000:d::a6]:54509 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25229 >> Windows doesn't suppport atomic renames if the right side exists. I >> suggest that you implement two code paths: >> >> if os.name == "posix": >> rename = os.rename >> else: >> def rename(a, b): >> try: >> os.rename(a, b) >> except OSError, e: >> if e.errno != 183: >> raise >> os.unlink(b) >> os.rename(a, b) > > Problem is if the process is stopped between unlink and rename there > would no status file. Yes, and actually it does not need to be an abnormal termination. It is enough if the OS scheduler puts this process on hold for some time... But using a lock file, the problem can be solved. However in that case, reading a status file can be a blocking operation.