[Python-Dev] MemoryError... how much memory?

Nick Coghlan ncoghlan at gmail.com
Thu Oct 28 15:39:12 CEST 2010


On Thu, Oct 28, 2010 at 11:14 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> Furthermore, our server is fairly complex: we're using quite some
>> libraries to do different jobs, and one of the approaches (not the
>> only one) that we're taking to deal with this beast is to analyze its
>> memory-related behaviour from an external POV (thinking it as a black
>> box).
>>
>> So, beyond it's arguable utility, do you think that having that
>> information could harm us in some way?
>
> I think implementing it might do harm. When a memory error is raised,
> you are typically out of memory, so allocating more memory might fail
> (it just did). Therefore, allocating more objects or doing string
> formatting will likely fail (unless the requested size is much larger
> than the memory required for these operations).
>
> So the chance increases that you trigger a fatal error.

What Martin describes here is a more explicit description of what I
meant by "practical implementation problems" and "special cases when
raising MemoryError". However, I think thresholding the additional
error formatting to only kick in the requested amount of memory
exceeds a certain size would be an adequate safeguard without reducing
the utility in Facundo's use case (the pre-allocated instance can have
a generic error message saying an allocation of less than the
threshold value failed).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list