Python Ioerror Cannot Allocate Memory Although There Is Plenty
Solution 1:
It looks to me like Python is just passing on an error from the underlying open()
call and the real culprit here is the Linux CIFS support - I doubt Python would be synthesizing ENOMEM
unless system memory was truly exhausted (and probably even then I'd expect the Linux OOM killer to be invoked instead of getting ENOMEM
).
Unfortunately it might need something of a Linux filesystem expert to figure out what's going on there, but looking at the sources for CIFS in the Linux kernel, I can see a variety of places where ENOMEM
is returned when various kernel-specific resources are exhausted as opposed to total system memory, but I'm not familiar enough with it to say how likely any of them are.
To rule out anything Python-specific you can run the process under strace
so you can see the exact return code that Python is getting from Linux. To do this, run your command something like this:
strace -eopen -f python myscript.py myarg1 myarg2 2>strace.log
The -f
will follow child processes (i.e. the jpeginfo
commands that you run) and the -eopen
will only show you open()
calls as opposed to all system calls (which is what strace
does by default). This could generate a reasonable amount of output, which is why I've redirected it to a file in the above example, but you can leave it displaying on your terminal if you prefer.
I would expect you'd see something like this just before you get your exception:
open("/path/to/file name.jpg", O_RDONLY) =-1 ENOMEM (Cannot allocate memory)
If so, this error is coming straight from the filesystem open()
call and there's very little you can do about it in your Python script. You could catch the exception and retry (perhaps after a short delay) as you're already doing if jpeginfo
fails, but it's hard to say how successful this strategy will be without knowing what's causing the errors in the first place.
You could, of course, copy the files locally, but it sounds like that would be a serious pain as there are so many.
EDIT: As an aside, you'll expect to see lots of open()
calls which are nothing to do with your script because strace
is tracing every call made by Python, which includes it opening its own .py
and .pyc
files, for example. Just ignore the ones which don't refer to the files you're interested in.
Post a Comment for "Python Ioerror Cannot Allocate Memory Although There Is Plenty"