Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95833
| References | <55e5b9ec$0$1649$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2015-09-02 00:57 +1000 |
| Subject | Re: Does mkstemp open files only if they don't already exist? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.45.1441119467.23514.python-list@python.org> (permalink) |
On Wed, Sep 2, 2015 at 12:45 AM, Steven D'Aprano <steve@pearwood.info> wrote: > I assume the answer is "Yes", but is it safe to expect that > tempfile.mkstemp() will only create a file that doesn't already exist? I > presume that there's no chance of it over-writing an existing file (say, > due to a race-condition). It depends on OS support, but with that, yes, it is guaranteed to be safe; the file is opened with an exclusivity flag. Check your system's man pages for details, or here: http://linux.die.net/man/3/open O_EXCL|O_CREATE makes an "atomic file creation" operation which will fail if another process is doing the same thing. I'm not sure how mkstemp() handles that failure, but my guess/expectation is that it would pick a different file name and try again. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Does mkstemp open files only if they don't already exist? Steven D'Aprano <steve@pearwood.info> - 2015-09-02 00:45 +1000 Re: Does mkstemp open files only if they don't already exist? Chris Angelico <rosuav@gmail.com> - 2015-09-02 00:57 +1000 Re: Does mkstemp open files only if they don't already exist? Laura Creighton <lac@openend.se> - 2015-09-01 19:09 +0200
csiph-web