Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25228
| 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 | <gandalf@shopzeus.com> |
| 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 <gandalf@shopzeus.com> |
| 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 <hansmu@xs4all.nl>, python-list@python.org |
| Subject | Re: How to safely maintain a status file |
| References | <CAOV1wRVtm27yWez1HZuN8=ia-TyM2aXp9QCUbSZ5aZExP_ZChA@mail.gmail.com> <sanjv7lo0vb3rlhip4ov1gpgp4gs51bvfr@invalid.netcom.com> <4FF9F454.40207@shopzeus.com> <jtcvf8$ock$1@dough.gmane.org> <mailman.2034.1342096256.4697.python-list@python.org> <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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2052.1342115003.4697.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
>> 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 "<stdin>", line 1, in <module>
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....
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: How to safely maintain a status file Laszlo Nagy <gandalf@shopzeus.com> - 2012-07-12 14:30 +0200
Re: How to safely maintain a status file Hans Mulder <hansmu@xs4all.nl> - 2012-07-12 15:19 +0200
Re: How to safely maintain a status file Laszlo Nagy <gandalf@shopzeus.com> - 2012-07-12 19:43 +0200
Re: How to safely maintain a status file Christian Heimes <lists@cheimes.de> - 2012-07-12 20:39 +0200
Re: How to safely maintain a status file Rick Johnson <rantingrickjohnson@gmail.com> - 2012-07-12 18:20 -0700
Re: How to safely maintain a status file Chris Angelico <rosuav@gmail.com> - 2012-07-13 12:12 +1000
Re: How to safely maintain a status file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 03:13 +0000
Re: How to safely maintain a status file Gene Heskett <gheskett@wdtv.com> - 2012-07-12 23:49 -0400
Re: How to safely maintain a status file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 04:21 +0000
Re: How to safely maintain a status file rantingrickjohnson@gmail.com - 2012-07-12 21:26 -0700
Re: How to safely maintain a status file Chris Angelico <rosuav@gmail.com> - 2012-07-13 16:02 +1000
Re: How to safely maintain a status file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-13 07:14 +0000
Re: How to safely maintain a status file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-13 13:29 -0400
RE: How to safely maintain a status file "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 16:00 +0000
Re: [Python] RE: How to safely maintain a status file Chris Gonnerman <chris@gonnerman.org> - 2012-07-13 12:27 -0500
RE: [Python] RE: How to safely maintain a status file "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-13 17:59 +0000
Re: [Python] RE: How to safely maintain a status file Hans Mulder <hansmu@xs4all.nl> - 2012-07-13 20:28 +0200
Re: [Python] RE: How to safely maintain a status file MRAB <python@mrabarnett.plus.com> - 2012-07-13 20:57 +0100
Re: [Python] RE: How to safely maintain a status file Christian Heimes <lists@cheimes.de> - 2012-07-13 22:21 +0200
Re: [Python] RE: How to safely maintain a status file Chris Angelico <rosuav@gmail.com> - 2012-07-14 04:19 +1000
RE: How to safely maintain a status file Chris Gonnerman <chris@gonnerman.org> - 2012-07-13 15:15 -0500
Re: How to safely maintain a status file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-14 01:53 +0000
csiph-web