By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,163 Members | 1,119 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,163 IT Pros & Developers. It's quick & easy.

fork after creating temporary file using NamedTemporaryFile

P: n/a
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


import os
import tempfile
import sys

cmd = []

foo = tempfile.NamedTemporaryFile(mode='w+b')

pid = os.fork()
if pid:
print 'I am parent'
print 'I am child'

$ python
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.

Jul 15 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
In message <g5*************>, Sebastian "lunar" Wiesner
Relying on the destructor is *always* a bad idea, you should always
close files explicitly!
There shouldn't be any problem with files opened read-only.
Jul 17 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.