It's so rare that Python behaves differently than we expect.
I had a bad experience today mixing apples and oranges.
import os
from msg import putmsg
def makeFifo(fifo):
os.system('rm -f ' + fifo)
os.system('/usr/sbin/mknod ' + fifo + ' p')
makeFifo('.foo1')
makeFifo('.foo2')
pid = os.fork()
if pid > 0:
fd1 = open('.foo1')
fd2 = open('.foo2')
os.wait()
else:
sticky = {}
sticky['ref'] = file('.foo1', 'w')
print sticky['ref'].fileno()
os.close(sticky['ref'].fileno())
fd2 = file('.foo2', 'w')
print fd2.fileno()
del sticky['ref']
putmsg(fd2.fileno(), 'control', 'data')os.close() frees up a file descriptor in the OS, for somebody else to use, but then when the file() object gets garbage collected, we try to close the same file descriptor. This happened to me in a much bigger program, took a while to track down. Now I know to call close() on the file() object.