test.py 469 B

12345678910111213141516171819202122
  1. import resource
  2. import traceback
  3. def limit_memory(maxsize):
  4. soft, hard = resource.getrlimit(resource.RLIMIT_AS)
  5. resource.setrlimit(resource.RLIMIT_AS, (maxsize, hard))
  6. if __name__=="__main__":
  7. limit_memory(20)
  8. try:
  9. list_a = []
  10. _i = 0
  11. while True:
  12. _i += 1
  13. print(_i)
  14. list_a.append("aaaaaaaaaaaaaaaaa")
  15. except Exception as e:
  16. print("Memory error 1")
  17. traceback.print_exc()