For the future readers that end up here, I figured that the problem in my case was that when I suspended a previous job using ctrl + z, the memory was not freed. Hence, I ran out of memory after a few runs. I used
ps -elf | grep python
to find the processes and killed them using
kill -9 [pid]
to free up the space. Here is a relative discussion 1.