[reportlab-users] Intermittent failure to find font, followed by IOError

Robin Becker robin at reportlab.com
Tue Jan 20 04:55:45 EST 2009


Stevens, Ian wrote:

> We've got a weird issue on our production boxes and I'm hoping someone

> might be able to shed some light. We're using Reportlab with Django to

> serve PDFs over HTTP. Any fonts which may be required are loaded before

> a PDF is built from Flowables. However, occasionally Reportlab appears

> to think a font isn't loaded, will execute a brute search for the

> required font and then fail when reading in one of Reportlab's stock

> fonts. The font in question is reportlab/fonts/LeERC___.AFM.

>

> This error is intermittent, which is bothersome, and always occurs from

> the same line, executed within a PageTemplate's onPage() method. Here's

> a stacktrace of the error:

>

>.......


Since Django is a long running process there is one possible situation in which
occasional font errors can occur.

request A loads font1 and uses it
request B just uses font1

If A is guaranteed to always occur first then no problem. There may be cases
when in fact that doesn't happen eg in high load situation django (or apache)
might just spawn a new thread or process that is not an exact copy of the
original. If the new process then just runs B there will be a problem.

To avoid this problem applications should really try and reset themselves to
some standard condition before running again.

We did some work with one of our long standing clients to improve throughput
using fcgi (instead of our more usual cgi) and found that we needed to provide a
reset mechanism for the toolkit and in addition some mechanism for ensuring that
any standard arguments to the app constructor are recreated afresh each time a
request gets handled.

Resetting of reportlab is done after each request using

from reportlab.rl_config import _reset
_reset()

this attempts to reset all the reportlab specific counters, caches etc etc so
that the reportlab library is in a standard state.
--
Robin Becker


More information about the reportlab-users mailing list