In python, tempfile.NamedTemporaryFile(...) creates a file "like" object that is visible in the fs.
mmap can read that file & treat it like an mmap would treat any normal file.
With a normal file, however, I can close the file, but still use the mmap (This is, in fact, true, though I'm not completely sure that it is safe). If I close the tempfile, it gets destroyed (
http://docs.python.org/library/tempfile.html). In my tests, I see that I can still read the file with the mmap after it is destroyed (which also works with regular files after they are deleted, assuming nothing in the fs has changed or the file isn't massively truncated).
My question is this, and I think I know the answer, but I'd like to be sure: Is it safe to use a map of a file that no longer exists (especially a tempfile)? If not (which I assume is the case), is there a way to tell if the mmap points at a valid file?
Second question along the same lines: Is it safe to use an mmap of a file who's file descriptor has been closed? i.e.:
Code:
fp = open("foo")
map = mmap.mmap(fp.fileno(),length=0,access=mmap.ACCESS_READ)
fp.close()
map.seek(map.size())