Mmap.error Errno 22 Invalid Argument
Contents |
Switch to make pprint.pprint display ints and longs in hex Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Bugs item #1341031, was opened mmap failed invalid argument psneuter at 2005-10-28 13:26 Message generated for change (Comment added) made by josiahcarlson You
Mmap Invalid Argument Offset
can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1341031&group_id=5470 Please note that this message will contain a full copy of the comment thread, man mmap including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.4 Status: Open Resolution: None Priority: 5 Submitted By: liturgist (liturgist) Assigned to: Nobody/Anonymous (nobody) Summary: mmap does not accept length as 0 Initial Comment: Creating an mmap object does not accept a length parameter of zero on Linux FC4 and Cygwin. However, it does on Windows XP. $ ls -al t.dat -rw-r--r-- 1 pwatson mkgroup-l-d 64 Oct 28 10:13 t.dat $ python Python 2.4.1 (#1, May 27 2005, 18:02:40) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import mmap >>> fp = open('t.dat', 'rb') >>> b = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ) Traceback (most recent call last): File "
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up mmap invalid argument error up vote 0 down vote favorite This is the first time I use mmap system call. I am getting invalid argument error and I do not understand why , obviously I missing something https://mail.python.org/pipermail/python-bugs-list/2005-November/030968.html Please help me, thank you #include
Post #1 of 4 (1127 views) Permalink bug? mmap doesn't http://www.gossamer-threads.com/lists/python/python/879210 like 0-length files mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) error: [Errno 22] https://bytes.com/topic/python/answers/645646-mmap-thoughts Invalid argument According to http://docs.python.org/library/mmap.html, mmap on _windows_ doesn't accept 0-length file. But this was tested on linux. Is this a bug? I don't see anything in linux man-page about the underlying C mmap function not accepting 0-length files. -- invalid argument http://mail.python.org/mailman/listinfo/python-list cs at zip Nov22,2010,6:59PM Post #2 of 4 (1113 views) Permalink Re: bug? mmap doesn't like 0-length files [In reply to] On 22Nov2010 20:33, Neal Becker <ndbecker2 [at] gmail> wrote: | mmap.mmap (f.fileno(), 0, prot=mmap.PROT_READ) | error: [Errno 22] Invalid argument | | According to http://docs.python.org/library/mmap.html, mmap on _windows_ | doesn't mmap.error errno 22 accept 0-length file. But this was tested on linux. Is this a bug? | | I don't see anything in linux man-page about the underlying C mmap function | not accepting 0-length files. On a local Gentoo Linux box mmap(2) says in the ERRORS section: EINVAL We don't like addr, length, or offset (e.g., they are too large, or not aligned on a page boundary). EINVAL (since Linux 2.6.12) length was 0. EINVAL flags contained neither MAP_PRIVATE or MAP_SHARED, or contained both of these values. Sure looks like a length of 0 is disliked. Cheers, -- Cameron Simpson <cs [at] zip> DoD#743 http://www.cskk.ezoshosting.com/cs/ Carpe Daemon - Seize the Background Process - Paul Tomblin <ab401 [at] freenet2> -- http://mail.python.org/mailman/listinfo/python-list cs at zip Nov22,2010,7:00PM Post #3 of 4 (1117 views) Permalink Re: bug? mmap doesn't like 0-length files [In reply to] On 23Nov2010 13:59, I wrote: | On 22Nov2010 20:33, Neal Becker <ndbecke&
& solutions from a community of 418,591 IT Pros & Developers. It's quick & easy. mmap thoughts P: n/a James T. Dennis 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 of it as been coding. Mostly it's just academic curiosity (I might be teaching an "overview of programming" class in a few months, and I'd use Python for most of the practical examples to cover a broad range of programming topics, including the whole concept of memory mapping used, on the one hand, as a file access abstraction and as a form of inter-process shared memory, on the other). Initial observations: * The standard library reference could use some good examples. At least of those should show use of both anonymous and named mmap objects as shared memory. * On Linux (various versions) using Python 2.4.x (for at least 2.4.4 and 2.4.2) if I create on mmap'ing in one process, then open the file using 'w' or 'w+' or 'w+b' in another process then my first process dies with "Bus Error" This should probably be documented. (It's fine if I use 'a' (append) modes for opening the file). * It seems that it's also necessary to extend a file to a given size before creating a mapping on it. In other words you can't mmap a newly created, 0-length file. So it seems like the simplest example of a newly created, non-anonymous file mapping would be something like: sz = (1024 * 1024 * 1024 * 2 ) - 1 f=open('/tmp/mmtst.tmp','w+b') f.seek(sz) f.write('\0') f.flush() mm = mmap.mmap(f.fileno(), sz, mmap.MAP_SHARED) f.close() Even creating a zero length file and trying to create a zero-length mapping on it (with mmap(f.fileno(),0,...) ... with a mind towards using mmap's .resize() method on it doesn't work. (raises: EnvironmentError: "Errno 22: Invalid Argument"). BTW: the call to f.flush() does seem to be required at least in my environments (Linux under 2.6 kernels various distributions and the aforementioned 2.4.2 and 2.4.4 versions of Python. * The mmtst.tmp file is "sparse" of course. So its size in the example above is 2GB ... but the disk usage (du command) on it is only a few KB (depending on your filesystem cluster size etc). * Using a function like len(mm[:]) forces the kernel's filesystem to ret