Question

I'm using a Python library (SimpleParse) that I seem to be causing some runaway recursion with it. It's already crashed my computer once when I was just trying to debug it.

What would be the best way for me to set some limits on how much memory it's using?

I was thinking I would write up a quick C program with setrlimit to call Python, and test it from there.

Was it helpful?

Solution

Python provides setrlimit(), so you can stay in Python. (Unless you're happier in C :)

Note that the Linux kernel hasn't supported the RSS accounting in a long time; the address space accounting is probably your best bet, but it might be overly restrictive. (If the program mmap(2)s a few gigabytes but never bothers reading or writing it, it won't really matter; the rlimits might forbid the mmap(2), rather than forbid actually using the memory.)

OTHER TIPS

Setting the recursion limit here is unlikely a reasonable solution. If the library has a bug, please report or fix it. If your code has an error, please fix it. SimpleParse is not widely used...you may look into other parser options. Since you did not explain what your real problem is that you are trying to solve there is little recommendation we can give on alternative tools.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top