fork after creating temporary file using NamedTemporaryFile
rparimi at gmail.com
rparimi at gmail.com
Tue Jul 15 10:15:54 EDT 2008
Hello pythoners,
When I create temporary file using the tempfile module, and forkI)
later on in my program, I always see errors when the program exits. Is
this because the child process deletes temp file?
Here's a stripped down version of my script that exhibits this
problem:
#!/usr/bin/python
import os
import tempfile
import sys
cmd = []
cmd.append('/bin/ls')
cmd.append('-l')
cmd.append('/tmp')
foo = tempfile.NamedTemporaryFile(mode='w+b')
pid = os.fork()
if pid:
print 'I am parent'
else:
print 'I am child'
sys.exit(0)
$ python sub.py
I am child
I am parent
Exception exceptions.OSError: (2, 'No such file or directory', '/tmp/
tmp-mZTPq') in <bound method _TemporaryFileWrapper.__del__ of <closed
file '<fdopen>', mode 'w+b' at 0xb7d2a578>> ignored
How can these warnings be avoided? I tried to catch this exception
using try/except but it didn't work.
thanks!
More information about the Python-list
mailing list