homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients Eduardo.Seabra, berker.peksag, georg.brandl, ncoghlan, pitrou, r.david.murray, serhiy.storchaka, socketpair, vstinner
Date 2015年12月21日.20:14:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450728841.97.0.919545935213.issue21579@psf.upfronthosting.co.za>
In-reply-to
Content
You'd have to do that anyway if we implemented a delete=False constructor argument, since you want it deleted if there are any errors, and that's not what a delete=False API would do. 
If it were me, I'd write it (untested)
 @contextlib.contextmanager
 def open_for_atomic_replace(fn):
 try:
 fd, name = tempfile.mkstemp()
 with io.open(fd) as fff:
 yield fff
 fff.flush()
 os.fdatasync(fff)
 os.rename(name, fn)
 except BaseException:
 os.unlink(name)
 raise
which would make your code simpler than it is now.
Naming it 'open_for_atomic_replace' reminded me of issue 8604, which is what you really want, not delete=False.
History
Date User Action Args
2015年12月21日 20:14:02r.david.murraysetrecipients: + r.david.murray, georg.brandl, ncoghlan, pitrou, vstinner, socketpair, berker.peksag, serhiy.storchaka, Eduardo.Seabra
2015年12月21日 20:14:01r.david.murraysetmessageid: <1450728841.97.0.919545935213.issue21579@psf.upfronthosting.co.za>
2015年12月21日 20:14:01r.david.murraylinkissue21579 messages
2015年12月21日 20:14:01r.david.murraycreate

AltStyle によって変換されたページ (->オリジナル) /