This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rbhkamal
Recipients rbhkamal
Date 2013-10-21.18:24:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382379885.04.0.64581281764.issue19337@psf.upfronthosting.co.za>
In-reply-to
Content
I was about to use memory mapping for something when I discovered that the code example posted on python.org causes python to core dump. %100 reproducible

The steps are really simple. 
1- Create a file and map it using mmap.mmap
2- In a while loop, contintously read the file
3- From another process, like bash, continuously write to the file.

After about 5 iterations from the reader, python core dumps.

Reader code (python):
#!/usr/bin/python2.7

import mmap
import time

with open("hello.txt", "wb") as f:
    f.write("Hello Python! 1234123412341234\n")

with open("hello.txt", "r+b") as f:
    # memory-map the file, size 0 means whole file
    mm = mmap.mmap(f.fileno(), 0)
    count=0
    while count < 100:
       mm.seek(0)
       print mm.readline()
       time.sleep(0.1)
       count = count + 1

    # close the map
    mm.close()


Writer code (linux shell/bash):
#!/bin/bash
count=0
while true
do
 ((count++))
 echo $count > hello.txt
done


Now run the reader, then launch the writer in a terminal. In my case I get the following output:
>110
>
>462
>
>Bus error (core dumped)


Python 2.7.3
Linux 3.2.0-54-generic #82-Ubuntu SMP Tue Sep 10 20:09:12 UTC 2013 i686 i686 i386 GNU/Linux
Ubuntu 12.04.3 LTS
Intel(R) Core(TM)2 CPU          6300  @ 1.86GHz
History
Date User Action Args
2013-10-21 18:24:45rbhkamalsetrecipients: + rbhkamal
2013-10-21 18:24:45rbhkamalsetmessageid: <1382379885.04.0.64581281764.issue19337@psf.upfronthosting.co.za>
2013-10-21 18:24:44rbhkamallinkissue19337 messages
2013-10-21 18:24:44rbhkamalcreate