[reportlab-users] IndexError exception in platypus.paraparser

Germán M. Bravo german.mb at gmail.com
Thu Dec 31 12:32:30 EST 2015


This definitely fixes the IndexError exception I've been getting.

I applied this monkey patch to fix it:

# FIXME: This monkeypatches rml2pdf.TTParagraphMixin so _parser is no longer
# a shared instance of TTParser class defined as a class property
rml2pdf.TTParagraphMixin._parser = property(lambda self: setattr(self,
'__parser', self.__dict__.get('__parser') or rml2pdf.TTParser()) or
self.__parser)


On Thu, Dec 31, 2015 at 1:35 AM, Germán M. Bravo <german.mb at gmail.com>
wrote:

> I'm working with ReportLab in a threaded environment and I've been getting
> a weird exception about IndexError when doing some operations such as
> _pop() during platypus.paraparser.ParaParser.end_br(). I think I've tracked
> the error down the fact _stack is a member of the TTParser instance (using
> rml2pdf).
>
> After googling around, I found a place where the source code of rml2pdf
> shows this:
>
> class TTParagraphMixin:
>     _CLEAN_SPACE = 0
>     _parser = TTParser()
>     ...
>
> Then, doing:
>
> from rlextra.rml2pdf import rml2pdf
> print(repr(rml2pdf.TTParagraphMixin._parser))
>
> confirms TTParser is an instance: <rlextra.rml2pdf.rml2pdf.TTParser
> instance at 0x1053eae18>
>
> This means TTParser instance there is an instance placed as a property of
> TTParagraphMixin at class level (which means it's shared by all instances
> of TTParagraph, TTXPreformatted and others) ...but (at least)
> TTParser._stack could be modified by several threads at the same time
> (causing the aforesaid exception to raise from time to time).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20151231/4ba9defd/attachment.html>


More information about the reportlab-users mailing list