Evgeny Roubinchtein
2000-01-20 06:38:01 UTC
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
temp file.
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
wondering).
def call_rvplayer(self):
l = []
for f in range(self.playlist.size()):
l.append('file://' + self.ra_dir + self.playlist.get(f) +
'.ra')
tn = tempfile.mktemp()
rf = tn + '.ram'
t = open(rf, 'w')
t.write(string.join(l, '\n'))
t.write('\n')
t.close()
pid = os.fork()
# XXX: how do I get rid of the temp file?
if pid == 0: # child
tempfile.template = None # per Library Reference
os.execv('/home/eroubinc/RealPlayerG2/realplay',
('/home/eroubinc/RealPlayerG2/realplay', rf))
else: # parent
self.playlist.delete(0, self.playlist.size())
return
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
temp file.
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
wondering).
def call_rvplayer(self):
l = []
for f in range(self.playlist.size()):
l.append('file://' + self.ra_dir + self.playlist.get(f) +
'.ra')
tn = tempfile.mktemp()
rf = tn + '.ram'
t = open(rf, 'w')
t.write(string.join(l, '\n'))
t.write('\n')
t.close()
pid = os.fork()
# XXX: how do I get rid of the temp file?
if pid == 0: # child
tempfile.template = None # per Library Reference
os.execv('/home/eroubinc/RealPlayerG2/realplay',
('/home/eroubinc/RealPlayerG2/realplay', rf))
else: # parent
self.playlist.delete(0, self.playlist.size())
return
--
Evgeny
Old mail has arrived.
Evgeny
Old mail has arrived.