Solved! Re: [Tutor] Getting rid of temp files after fork/exec?
Thu, 20 Jan 2000 15:56:20 -0800 (PST)
I think I got it now. My solution was to call fork() twice, like so:
# cut --- rest of function unchanged. --- cut
pid = os.fork()
if pid == 0: # first child
tempfile.template = None # per Library Reference
pid2 = os.fork()
if pid2 == 0: # grandhild -- exec the program
else: # child - wait on grandchild, then remove the file
(p, s) = os.waitpid(pid2, 0)
else: # parent
The child does become a zombie in this scheme, but not for long; does this
have any similarity to what is normally done?
On Wed, 19 Jan 2000, Evgeny Roubinchtein wrote:
ER> This is Unix-specific, but since I understand many people on this list
ER> use Linux/Unix I thought I'd ask.
ER> I have a function that writes some data to a temp file, then fork()s; the
ER> child execv()s a program passing to it the name of the temp file as an
ER> argument, and the parent does some cleanup in the GUI and then returns.
ER> The problem is that leaves the temp file around, since the execv() doesn't
ER> really return, and I don't like that. I thought this was a common enough
ER> thing that someone might know what people normally do to get rid of the
ER> temp file.
ER> For reference, here's the function's code (it's part of a simple GUI to
ER> select a bunch of files to play with RealAudio Player, in case you are
ER> def call_rvplayer(self):
ER> l = 
ER> for f in range(self.playlist.size()):
ER> l.append('file://' + self.ra_dir + self.playlist.get(f) +
ER> tn = tempfile.mktemp()
ER> rf = tn + '.ram'
ER> t = open(rf, 'w')
ER> t.write(string.join(l, '\n'))
ER> pid = os.fork()
ER> # XXX: how do I get rid of the temp file?
ER> if pid == 0: # child
ER> tempfile.template = None # per Library Reference
ER> ('/home/eroubinc/RealPlayerG2/realplay', rf))
ER> else: # parent
ER> self.playlist.delete(0, self.playlist.size())
ER> Old mail has arrived.
ER> Tutor maillist - Tutor@python.org
A)bort, R)etry, I)gnore, V)alium?