MemoryError crashes within try clause

Phil Mayes nospam at bitbucket.com
Mon Jun 5 17:58:53 EDT 2000


The following code sample is designed to consume memory, and crashes
under Win98.  If the try clause is removed or moved to a calling
function, a MemoryError is generated as expected??!

This is not an academic question; I arrived here through tracking hangs
in a beta release under low-memory conditions.  Any clues or insights
gratefully received.

Thanks, Phil

Configuration: Python 1.5.2, Pentium, 64MB, Win98 with virtual memory
turned off.

---------- code sample follows --------
"""
%1 caused an invalid page fault in
module %2 at %3!.04x!:%4!.08x!.
Registers:
EAX=%1!.08x! CS=%2!.04x! EIP=%3!.08x! EFLGS=%4!.08x!
"""

def GetBigList():
    size = 1 << 20
    while size:
        try:
            return [None] * size
        except:
            size = size / 2

def UseMostMemory():
    s = 'x' * 32000
    list = GetBigList()
    print 'UseMostMemory list size =',len(list)
    try:
        for x in xrange(len(list)):
            list[x] = s+str(x)
            print x
    except:
        print 'failed at',x
    return list

def Eat():
    try:
        list = GetBigList()
        print 'Eat list size =',len(list)
        eaten = UseMostMemory()
        x = 0
        while x < len(list):
            list[x] = str(x)
            if x %100 == 0:
                print x
            x = x + 1
    except:
        pass

try:
    Eat()
except:
    print 'fail'
--
Phil Mayes    pmayes AT olivebr DOT com
Olive Branch Software - home of Arranger
http://www.olivebr.com/






More information about the Python-list mailing list