Grant Edwards schreef op 2015-04-30 18:33:
On 2015-04-30, Cecil Westerhof <ce...@decebal.nl> 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?

I presume "don't do that" has already occured to you?

A few weeks ago, I had a bug in a Python script which caused it to consume all memory, thrashed my computer; the system become unresponsive and it was very difficult to kill the process and get everything back in working order.

Then I thought (foolishly) that the bug was fixed, so I ran the script again, with the same disastrous results. And then again. Stupid, I know.

A way to limit memory usage would have been nice: the script would have been killed before it could grind the whole system to a halt.

You can always use ulimit to limit the memory allowed for the process
running Python.

Sadly in my case the OS is Windows, and as far as I know it doesn't have a ulimit equivalent for limiting memory usage.

I guess I could have used 32-bit Python instead of 64-bit Python to limit available memory.


--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to