mmap file won't open properly with Linux

Parzival ConfuseYourSpamBot-parzp at ConfuseYourSpamBot.shaw.ca
Sat Nov 8 15:21:04 EST 2003


I have a program which works well on under Windows, which
I am trying to get to work under Linux (Mandrake 9.1)

It accesses a binary file with mmap. Under Windows,
the file maps and reads withut porblems, but under linux
an attempt to access the mapped data fails with a cryptic
error message. I thought that perhaps the file
was corrupted, so I recreated it in my Linux environment
and examined it with a hex editor, and it appears to be
perfect.

The mmap call does not raise an exception, so how can
the subsequent access to the fail?

Traceback (most recent call last):
  File "./ACSatlasBuilder.py", line 292, in ?
    acs.writeAll(limit=None)
  File "./ACSatlasBuilder.py", line 45, in writeAll
    header += self.writeLocations(fin, fout, limit)
  File "./ACSatlasBuilder.py", line 65, in writeLocations
    ACS = Tz.TzDatabase("ACStt.dat")
  File "/home/parz/xAtlas/Tz.py", line 25, in __init__
    header = struct.unpack(">16i", self.Map[0:16*4])
ValueError: mmap closed or invalid


Here is the relevant portion of the program source:

DefTzFile = "Ott.dat"

class TzDatabase:

    minyear = idt.date(1830)
    magic0 = 0x108bead + 0
    magic1 = 0x108bead + 1
    nsegments = 4

    def __init__(self, filename=DefTzFile):
        self.filename = filename
        self.fd = os.open(filename, os.O_RDONLY)
        self.Map = mmap.mmap(self.fd, 0, access=mmap.ACCESS_READ)

#### exception occurs here:  #####
        header = struct.unpack(">16i", self.Map[0:16*4])
        if header[0] == self.magic0:
            self.ztSeg, self.ttSeg, self.txSeg, self.znSeg =
range(self.nsegments)
        elif header[0] == self.magic1:
            self.ttSeg, self.txSeg, self.ztSeg, self.znSeg =
range(self.nsegments)
        else:
            assert False, 'File %s is not a TzDatabase file' % filename


(-: Stop, smile, and enjoy your breathing :-)
-- Parzival
-- Reply-to is confuggled: parzp (@) shaw (.) ca





More information about the Python-list mailing list