Access violation when no memory

Vladimir Marangozov Vladimir.Marangozov at inrialpes.fr
Thu Jun 22 10:29:49 EDT 2000


Phil Mayes wrote:
> 
> No, I understand that - my program is explicitly designed to consume
> all memory by progressively consuming smaller and smaller blocks,
> throwing exceptions at each size.

Whatever your task is, I strongly doubt that consuming all the memory
of your machine is really what you want to do. Not from Python, at least.

The net effect of your program is zeroing the memory the OS is kind enough
to allocate for Python. It's not really Python's fault in such extreme
situations. Tim Peters reported (and one could try it easily with a
malloc(BIG) call) that Linux overbooks it's memory, that is, the malloc
succeeds, but accessing everything subsequently segfaults because the
requested mem size is not physically present (RAM + swap included).

So this boils down on how the OS handles such extreme cases. Python
usually does not trap OS signals, etc. and it cannot handle OS-level
mem overflows. All it does is trusting C malloc and checking the return
values for success or failure.

> My point is that eventually Python /crashes/ by attempting to write to
> low memory instead of failing with a MemoryError.

You get what you asked for <wink>. See above why.

> 
> So I need a ceval.c expert to vet my change.
>

Forget about it <wink>. Nobody is convinced that checking for NULL the
top of stack after popping its value would solve any problem. Your example
crashes on my combo in the builtin dict methods (& elsewhere). This is
really low-level OS stuff, and Python has not builtin emergency procedures
for these cases. I don't know why you want to eat all your memory, but
I'd suggest changing the approach or write a C module that deals with
the memory issues you're looking for.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov at inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252



More information about the Python-list mailing list