Reportlab Image object opens filehandles

Discussion in 'Python' started by Michael Schmitt, Sep 10, 2003.

  1. 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)
    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 Schmitt, Sep 10, 2003
    1. Advertisements

  2. Michael Schmitt

    Tim Hoffman Guest

    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.


    Tim Hoffman, Sep 10, 2003
    1. Advertisements

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

    Michael Schmitt, Sep 10, 2003
  4. Michael Schmitt

    Robin Becker Guest

    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 import File
    self._image =
    import PIL.Image
    self._image =

    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.
    Robin Becker, Sep 11, 2003
  5. Michael Schmitt

    Robin Becker Guest

    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.
    Robin Becker, Sep 12, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.