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.

classification
Title: tempfile.mktemp() omits pid from name
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ganssauge, georg.brandl, theller
Priority: normal Keywords:

Created on 2003-12-10 13:53 by ganssauge, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg19355 - (view) Author: Gottfried Ganßauge (ganssauge) Date: 2003-12-10 13:53
In python2.2 names created using tempfile.mktemp() 
contained the current pid as a prefix.
This behaviour has changed and now processes running 
concurrently are prone to races.
1.) In my application which forks a few thousand sub 
processes over time sometimes tempfiles created by one 
subprocess are deleted by another.
2.) Also this probably leads to longer creation times 
when two processes want to create a temp file at the 
same time on multiprocessor machines because both 
processes are using the same rng with the same seed to 
generate names.
Sorry, no code here, because 1. happens only a few 
times when running with huge amounts of data and 
because 2. is only a speculation.

I would propose to reinstate the former behaviour.
msg19356 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-12-10 14:04
Logged In: YES 
user_id=11105

mktemp() is deprecated in 2.3, to prevent exactly the
problems you have.  Read the docs, and use mkstemp() instead.
msg19357 - (view) Author: Gottfried Ganßauge (ganssauge) Date: 2003-12-10 14:17
Logged In: YES 
user_id=792746

This is no option.
In our system we need to spawn another program which 
doesn't accept file handles but wants to have a filename 
instead.
msg19358 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-12-10 15:56
Logged In: YES 
user_id=11105

Well, you could close the file (or even remove it, depending
on your requirements), and pass the filename to the spawned
program.

Or, if you insist on using mktemp(), pass a prefix argument
yourself?

But I'm not really sure if this is what you need, so this is
my last comment.
msg19359 - (view) Author: Gottfried Ganßauge (ganssauge) Date: 2003-12-11 10:29
Logged In: YES 
user_id=792746

It is already hard to keep a system working in a changing 
world, so I see no necessity to needlessly introduce 
incompatibilities.
Your comments are apreciated nonetheless.
msg19360 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-25 20:21
Logged In: YES 
user_id=1188172

Closing this as Won't Fix, as mktemp is really deprecated
now and shouldn't be used.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39688
2003-12-10 13:53:44ganssaugecreate