Get Python to raise MemoryError instead of eating all my disk space

Posted by asmeurer on Super User See other posts from Super User or by asmeurer
Published on 2012-11-20T23:56:04Z Indexed on 2012/12/15 5:10 UTC
Read the original article Hit count: 443

Filed under:
|
|
|

If I run a Python program with a memory leak, I would normally expect the program to eventually die with MemoryError. But instead, what happens is that all the virtual memory is used until my disk runs out of space. I am running Mac OS X 10.8 on a retina MacBook Pro. My computer generally has between 10GB to 20GB free. Mac OS X is smart enough to not die completely when the disk runs out of space (rather, it gives me a dialog letting me force quit my GUI programs).

Is there a way to make Python just die when it runs out of real memory, or some reasonable amount of virtual memory? This is what happens on Linux, as far as I can tell. I guess Mac OS X is more generous than Linux with virtual memory (the fact that I have an SSD might be part of this; I don't know just how smart OS X is with this stuff). Maybe there's a way to tell the Mac OS X kernel to never use so much virtual memory that leaves less than, say, 5 GB free on the hard drive?

© Super User or respective owner

Related posts about mac

Related posts about python