l = range(int(1E9))

Dave Angel davea at davea.name
Thu Apr 30 14:59:42 EDT 2015


On 04/30/2015 02:48 PM, alister wrote:
> On Thu, 30 Apr 2015 20:23:31 +0200, Gisle Vanem wrote:
>
>> Cecil Westerhof wrote:
>>
>>> If I execute:
>>>       l = range(int(1E9)
>>>
>>> The python process gobbles up all the memory and is killed. The problem
>>> is that after this my swap is completely used, because other processes
>>> have swapped to it. This make those programs more slowly. Is there a
>>> way to circumvent Python claiming all the memory?
>>>
>>> By the way: this is CPython 2.7.8.
>>
>> On what OS? If I try something similar on Win-8.1 and CPython 2.7.5
>> (32-bit):
>>
>>    python -c "for i in range(int(1E9)): pass"
>>     Traceback (most recent call last):
>>       File "<string>", line 1, in <module>
>>     MemoryError
>>
>>
>> --gv
>
> also MemoryError on Fedora 21 32 bit
>

That's presumably because you end up running out of address space before 
you run out of swap space.  On a 64 bit system the reverse will be true, 
unless you have a really *really* large swap file

ulimit is your friend if you've got a program that wants to gobble up 
all of swap space.

-- 
DaveA



More information about the Python-list mailing list