Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'f.close()': 0.07; 'raises': 0.07; 'rename': 0.07; 'subject:file': 0.07; 'subject:How': 0.09; 'worked.': 0.09; 'file,': 0.15; 'atomic.': 0.16; 'posix': 0.16; 'exists': 0.17; 'skip': 0.17; '>>>': 0.18; 'windows': 0.19; 'file.': 0.20; 'import': 0.21; '"",': 0.22; 'exists.': 0.22; 'work.': 0.23; 'to:2**1': 0.23; 'seems': 0.23; 'linux': 0.24; 'tried': 0.25; 'least': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; '(most': 0.27; 'operations,': 0.27; 'implicitly': 0.29; 'question:': 0.29; 'error': 0.30; 'file': 0.32; 'not.': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'received:192.168.0': 0.35; 'there': 0.35; 'but': 0.36; 'wanted': 0.36; "didn't": 0.36; 'should': 0.36; 'does': 0.37; 'two': 0.37; 'systems,': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'back': 0.62; 'received:62': 0.62; 'race': 0.71; '[error': 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; 'stop,': 0.84; 'subject:status': 0.84 X-SourceIP: 89.134.225.226 Date: Thu, 12 Jul 2012 19:43:19 +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: Hans Mulder , python-list@python.org Subject: Re: How to safely maintain a status file References: <4FF9F454.40207@shopzeus.com> <4ffecef4$0$6877$e4fe514c@news2.news.xs4all.nl> In-Reply-To: <4ffecef4$0$6877$e4fe514c@news2.news.xs4all.nl> 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342115004 news.xs4all.nl 6892 [2001:888:2000:d::a6]:45958 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25228 >> This is not a contradiction. Although the rename operation is atomic, >> the whole "change status" process is not. It is because there are two >> operations: #1 delete old status file and #2. rename the new status >> file. And because there are two operations, there is still a race >> condition. I see no contradiction here. > On Posix systems, you can avoid the race condition. The trick is to > skip step #1. The rename will implicitly delete the old file, and > it will still be atomic. The whole process now consists of a single > stop, so the whole process is now atomic. Well, I didn't know that this is going to work. At least it does not work on Windows 7 (which should be POSIX compatible?) >>> f = open("test.txt","wb+") >>> f.close() >>> f2 = open("test2.txt","wb+") >>> f2.close() >>> import os >>> os.rename("test2.txt","test.txt") Traceback (most recent call last): File "", line 1, in WindowsError: [Error 183] File already exists >>> I have also tried this on FreeBSD and it worked. Now, let's go back to the original question: >>>This works well on Linux but Windows raises an error when status_file already exists. It SEEMS that the op wanted a solution for Windows....