Issue 1390197: tempfile misses usecase which requirs renaming (original) (raw)

Issue1390197

Created on 2005-12-25 20:41 by dallison, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg61216 - (view) Author: Dennis Allison (dallison) Date: 2005-12-25 20:41
tempfile provides a very convenient API but it seems to miss one important use case. For example, suppose the program is stream editing the file. Typically one reads the source file, edits the data, and writes it to a temporary file. Upon successful completion of the edit, the program renames the temporary to be the original source file, which is atomic in most operating systems, There does not appear to be any neat way to do this with the current API without the program throwing an exception because of the deletion wrapper. Perhaps a "rename" method needs to be added to manage the delete seamlessly. I am not especially fond of that solution as it adds new functionality to file descriptors. .
msg67680 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-06-04 02:54
If you mean "renaming the temporary file while it is still opened" I see 2 reasons for not doing that: - On Windows this is not possible since files remains locked as long as you close() them. - open().name and tempfile.NamedTemporaryFile().name attributes are not reliable since they remains the same even after the file renaming. >>> import os >>> f = open('1', 'w') >>> os.rename('1', '2') >>> f.name 1
msg114594 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-21 23:02
Closing due to questionable usecase.
msg114598 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-21 23:06
Maybe #8828 or #8604 are what you’re looking for.
History
Date User Action Args
2022-04-11 14:56:14 admin set github: 42728
2010-08-21 23:06:18 eric.araujo set nosy: + eric.araujomessages: +
2010-08-21 23:02:25 georg.brandl set status: open -> closednosy: + georg.brandlmessages: + resolution: rejected
2008-06-04 02:54:17 giampaolo.rodola set nosy: + giampaolo.rodolamessages: +
2005-12-25 20:41:19 dallison create