I have the following block in my python script that is running on an Ubuntu AWS EC2 instance:
try:
data = json.loads(line)
# further processing of data
except Exception, e:
# something went bad
line
is a string ingested from a text file. In most cases it gets processed fine. From time to time, I get lines that are humongous. In this case the script dies ("-9") and dmesg -T
shows a message like [Tue Jan 8 16:10:48 2013] Out of memory: Kill process 13609 (python) score 910 or sacrifice child
What I don't understand is why instead of crashing it does not catch an exception in the try-except
block. And is it possible to make changes in this block so that the script does not crash but raises and exception? Thx