Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > mmap file won't open properly with Linux

Reply
Thread Tools

mmap file won't open properly with Linux

 
 
Parzival
Guest
Posts: n/a
 
      11-08-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

 
Reply With Quote
 
 
 
 
Jeff Epler
Guest
Posts: n/a
 
      11-08-2003
Read the documentation more carefully. The "0 means length of file"
trick only works on windows, apparently.

You can use os.fstat(fd).st_size to get the current size of an open
file, or os.stat(filename).st_size to get the current size of a file by
name.

Jeff

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mmap'ing the same file Alexandru Palade C Programming 3 08-03-2011 03:38 PM
Powerpc I/O memory, linux, mmap and eieio Manu C Programming 0 05-14-2008 10:43 AM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
mmap -- memory mapped file Carl Mackey Python 1 06-29-2006 04:34 AM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM



Advertisments