[reportlab-users] intermittent problem
robin at reportlab.com
Wed Jun 6 11:18:17 EDT 2012
On 06/06/2012 15:33, Jens Lundström wrote:
> I am using Django 1.4 / Python 2.7 / reportlab (open source version) to generate pdf.
> Things have worked really great and I do pdf generation (as in http requested returned/downloaded generated pdf file) within Django 1.3 but now upgraded to Django 1.4 and now starting to get problems. They seem to be 'random' as it works most of the time but now and again I get 'random' problems (as in I see there are exceptions once in a while in logs) but I have never been able to reproduce problems myself (things works most of the time), the reports are generated using static information so each time the same fix data is accessed and used to generate reports.
> What I get is the following type of errors that always happens in pairs
> Exception Value: ParaParser instance has no attribute '_seq'
> Exception Location: /home/tss/lib/python2.7/reportlab-2.5-py2.7-linux-i686.egg/reportlab/platypus/paraparser.py in _complete_parse, line 1061
> and then
> Exception Value: 'NoneType' object has no attribute 'close'
> Exception Location: /home/tss/lib/python2.7/reportlab-2.5-py2.7-linux-i686.egg/reportlab/lib/xmllib.py in close, line 521
> I have also seen this error on its own:
> Exception Value: list index out of range
> Exception Location: /home/tss/lib/python2.7/reportlab-2.5-py2.7-linux-i686.egg/reportlab/platypus/paraparser.py in _push, line 941
> Given that I am having a hard time reproducing this and not sure if problem on my side or reportlab - I am open for suggestions on how to troubleshoot this (could it be sync issue as in many generating conccurently or just a plain bug or...) ???
> / Jens
I'm almost sure this is an issue with django+threading or similar versus
reportlab. As has been made very clear many times in this list reportlab is not
thread safe. There is supposed to be a single instance of ParaParser, but multi
threaded programs will possibly not like that.
We do use reportlab with django, but we are using a multiple (ie forked) process
setup (definitely no threading). That works for a specific application ie
repeated setup costs may be wasted, but they're never inconsistent. For multiple
documents even the multiple process django may give rise to strange bugs. The
processes get reused so unless you insist on trying to re-initialize all of
reportlab then there may be cases when one document setup accidentally
initializes for a second one; if the processing order is reversed then the
accident never happens and the document may fail or look wrong. ReportLab does
have hooks to support fastcgi using re-initialization ie there's a function in
reportlab.rl_config called _reset that attempts to set things back to zero, but
even that isn't guaranteed.
More information about the reportlab-users