473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

mmap file won't open properly with Linux

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

Jul 18 '05 #1
1 3967
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

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
1
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
1
by: Carl Mackey | last post by:
hi, i'm new to this list and new to python as well. i have a question on the memory mapped file ability python has. when i use a mmap on a file, will it copy the whole thing to ram or just...
26
by: myeates | last post by:
Hi Anyone ever done this? It looks like Python2.4 won't take a length arg Mathew
2
by: beejisbrigit | last post by:
Hi there, I was wondering if anyone had experience with File I/O in Java vs. C++ using mmap(), and knew if the performance was better in one that the other, or more or less negligible. My...
1
by: James T. Dennis | last post by:
I've been thinking about the Python mmap module quite a bit during the last couple of days. Sadly most of it has just been thinking ... and reading pages from Google searches ... and very little...
2
by: Neal Becker | last post by:
On linux, I don't understand why: f = open ('/dev/eos', 'rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) gives 'permission denied', but...
0
by: Akira Kitada | last post by:
Hi Marc-Andre, Thanks for the suggestion. I opened a ticket for this issue: http://bugs.python.org/issue4204 Now I understand the state of the multiprocessing module, but it's too bad to see...
0
by: M.-A. Lemburg | last post by:
On 2008-10-25 20:19, Akira Kitada wrote: Thanks. The errors you are getting appear to be related to either some missing header files or a missing symbol definition to enable these - looking...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.