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

Stevens, Ian IStevens at globeandmail.com
Tue Oct 27 16:34:33 EDT 2009

Hi all. Earlier this year, I posted a problem we had been having with our production servers. We were getting an intermittent "IOError: Cannot open resource '/usr/lib/python2.5/site-packages/reportlab/fonts/LeERC___.AFM'":


We weren't able to reproduce it at all, but it persisted. We upgraded to Reportlab 2.3, and it still persisted. I added a suggested call to reportlab.rl_config._reset() (see http://two.pairlist.net/pipermail/reportlab-users/2009-January/007933.html) before any fonts are registered. The error still persists:

File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfmetrics.py", line 226, in bruteForceSearchForAFM
(topDict, glyphDict) = parseAFMFile(possible)

File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfmetrics.py", line 79, in parseAFMFile
lines = open_and_readlines(afmFileName, 'r')

File "/usr/lib/python2.5/site-packages/reportlab/lib/utils.py", line 459, in open_and_readlines
return open_and_read(name,mode).split('\n')

File "/usr/lib/python2.5/site-packages/reportlab/lib/utils.py", line 456, in open_and_read
return open_for_read(name,mode).read()

File "/usr/lib/python2.5/site-packages/reportlab/lib/utils.py", line 452, in open_for_read
raise IOError('Cannot open resource "%s"' % name)

IOError: Cannot open resource "/usr/lib/python2.5/site-packages/reportlab/fonts/DarkGardenMK.afm"

Recently we set Apache's MaxRequestsPerChild to 1 (while using mpm_prefork_module) to determine if the problem was indeed state-related. Under that configuration, none of the above errors appeared. Unfortunately, that setup isn't conducive to a high-performing web server so it had to be removed. While before these errors were only slightly annoying, we're under increasing traffic and so they are increasing in frequency.

Under what conditions would reportlab.lib.utils.open_for_read_by_name() fail on a local file? On our server, it would just be a call to open().

We are running Reportlab in Django under Apache with mpm_prefork_module and mod_python. Every request for a PDF first registers a combination of about 65 app-specific Postscript and TrueType fonts before any other Reportlab operations. Adding reportlab.rl_config._reset to the top of that method had no effect.

Andy (Robinson) wrote that we could help investigate this error by adding some trace statements in the code. Unfortunately, we haven't been able reproduce the errors. We are open to adding this code for a few days and delivering the results. We are running off the release version of 2.3. Would you be able to provide us with some patches which we could apply?


More information about the reportlab-users mailing list