[Tutor] Getting rid of temp files after fork/exec?
Wed, 19 Jan 2000 22:38:01 -0800 (PST)
This is Unix-specific, but since I understand many people on this list
use Linux/Unix I thought I'd ask.
I have a function that writes some data to a temp file, then fork()s; the
child execv()s a program passing to it the name of the temp file as an
argument, and the parent does some cleanup in the GUI and then returns.
The problem is that leaves the temp file around, since the execv() doesn't
really return, and I don't like that. I thought this was a common enough
thing that someone might know what people normally do to get rid of the
For reference, here's the function's code (it's part of a simple GUI to
select a bunch of files to play with RealAudio Player, in case you are
l = 
for f in range(self.playlist.size()):
l.append('file://' + self.ra_dir + self.playlist.get(f) +
tn = tempfile.mktemp()
rf = tn + '.ram'
t = open(rf, 'w')
pid = os.fork()
# XXX: how do I get rid of the temp file?
if pid == 0: # child
tempfile.template = None # per Library Reference
else: # parent
Old mail has arrived.