0

I want to Know how can I make my python program run in such a say that it takes only specified amount of memory (say x bytes) to run, and in case of it requires more memory than x it should be terminated.

I want something like this:

if memory_required > x:
        Terminate program
else:
         Let the program run
Mayank Joshi
  • 57
  • 1
  • 9
  • I think you'e just maxing out your system. My OS (macOS) reports (and counting)) 60GB of memory usage for Python. This is probably uncompressed and with swap as my system only has 8GB of real memory but I'm not surprised your system slows down. - Update macOS killed the process to protect itself. – Sven van de Scheur Oct 07 '18 at 12:59
  • What can I do in case I want to terminate this execution? – Mayank Joshi Oct 07 '18 at 13:02
  • Try Ctrl+D or run 'killall python' in another terminal. Note: the last wil kill every python process running. – Sven van de Scheur Oct 07 '18 at 13:03
  • The problem is that nothing works, python become unfunctional – Mayank Joshi Oct 07 '18 at 13:04
  • 3
    You just requested at least 16 _million terabytes_ of storage - probably more, depending on how much space `list` instances take and stuff. What did you expect, then? Do you have that much storage on your machine? If it's still unresponsive, you may have to manually unplug it. – ForceBru Oct 07 '18 at 13:11
  • @ForceBru does it mean that a 2d list of size 10^9 can't be declared – Mayank Joshi Oct 07 '18 at 13:13
  • I was Trying this declaration for competitive programming – Mayank Joshi Oct 07 '18 at 13:13
  • @MayankJoshi, as you can see, the language lets you _declare_ lists as huge as you want them to be. However, the actual _computer_ that'll attempt to _execute_ this code may run out of memory. – ForceBru Oct 07 '18 at 13:14
  • Possible duplicate of [Limit memory usage?](https://stackoverflow.com/questions/30269238/limit-memory-usage) – Nearoo Oct 07 '18 at 14:59

0 Answers0