Reportlab Image object opens filehandles

M

Michael Schmitt

Hello.

I am trying to build a pdf document using:
---
from reportlab.platypus.flowables import Image
lst = []
for filename in imageFiles:
I= Image(filename, width= 300, height= 300)
lst.append(I)
---
Creating an Image object seems to open a filehandle, so if the size of
imageFiles increases, I get "IOError: [Errno 24] Too many open files" on a
Solaris machine, where the number of simultaneously opened filehandles
seems to be limited to roughly 255.

Is there a way to produce a pdf document with a large number of images
without running into the problem of too many open filehandles?

Thanks for any hints.
Michael
 
T

Tim Hoffman

Have a look at limit (or in csh ulimit)

256 open files is the default limit for a user/process. (all about
conserving resources) you can make this bigger (much bigger ;-) assuming
you have permissions.

Rgds

Tim
 
M

Michael Schmitt

Tim said:
Have a look at limit (or in csh ulimit)

256 open files is the default limit for a user/process. (all about
conserving resources) you can make this bigger (much bigger ;-) assuming
you have permissions.

Rgds
Hello Tim.
unfortunately changing this limit is not an option for me.

Thanks.
Regards,
Michael
 
R

Robin Becker

Michael Schmitt said:
Hello.

I am trying to build a pdf document using:
---
from reportlab.platypus.flowables import Image
lst = []
for filename in imageFiles:
I= Image(filename, width= 300, height= 300)
lst.append(I)
---
Creating an Image object seems to open a filehandle, so if the size of
imageFiles increases, I get "IOError: [Errno 24] Too many open files" on a
Solaris machine, where the number of simultaneously opened filehandles
seems to be limited to roughly 255.

Is there a way to produce a pdf document with a large number of images
without running into the problem of too many open filehandles?

Thanks for any hints.
Michael

We've recently begun changing the code for images to assist in a port to
jython. I believe the problem still exists.

in the ImageReader __init__ we have code like

#detect which library we are using and open the image
if sys.platform[0:4] == 'java':
from javax.imageio import ImageIO
from java.io import File
self._image = ImageIO.read(File(fileName))
else:
import PIL.Image
self._image = PIL.Image.open(fileName)

I guess the problem here is that we don't open or close the file
explicitly in our code. I think that we could delay opening the image
until it's actually needed. PIL's open doesn't seem to explicitly close
its files.

If a document had 300 images we'd currently have all those file pointers
open before rendering started and the Image object could be thrown away.

Unfortunately the reportlab.platypus.Image flowable class want's to open
the image in it's init so there wouldn't be much delay unless we push
the laziness in there as well.

I will copy this into the reportlab-users list for others to comment on.
 
R

Robin Becker

Michael Schmitt said:
Hello.

I am trying to build a pdf document using:
---
from reportlab.platypus.flowables import Image
lst = []
for filename in imageFiles:
I= Image(filename, width= 300, height= 300)
lst.append(I)
---
Creating an Image object seems to open a filehandle, so if the size of
imageFiles increases, I get "IOError: [Errno 24] Too many open files" on a
Solaris machine, where the number of simultaneously opened filehandles
seems to be limited to roughly 255.

Is there a way to produce a pdf document with a large number of images
without running into the problem of too many open filehandles?

Thanks for any hints.
Michael
I have implemented an attempt at a lazy platypus Image, but haven't time
to test it right now. If you contact me I can send it you directly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top