[reportlab-users] Generating huge reports and memory consumption

Alessandro Praduroux reportlab-users@reportlab.com
Fri, 3 Jan 2003 18:38:52 +0100


On Friday 03 January 2003 16:13, Robin Becker wrote:
> In article <200301031506.15211.pradu@pradu.it>, Alessandro Praduroux
> <pradu@pradu.it> writes
>
> >Hi all
>
> .....This is clearly of interest. There used to be something written by
> Tim Peters to detect cycles. I think it's called Cyclops.py and it may
> help. If you can't locate it I will post it.
>

I found 0.9.4, here the results:

>>> import Cyclops
>>> import avviso
>>> z = Cyclops.CycleFinder()
>>> z.run(avviso.main)
>>> z.find_cycles(purge_dead_roots=0)
0
>>> z.show_stats()
**********************************************************************
# objects in root set: 184091
# distinct structured objects reachable: 350224
# distinct structured objects in cycles: 0
# cycles found: 0
# cycles filtered out: 0
# strongly-connected components: 0
# arcs examined: 2206833
>>> z.show_cycles()
**********************************************************************
# all cycles:


> From the fragment you give it seems as though the story isn't being
> reset, but I may be missing something.
>
after the build(), I checked and self.Story was empty. I believe build() 
"consumes" the story

> Can you say which constructs are being used?
>
This is what I do to build each page of the story:

        lines = text.split('\n')
        self.Story.append(Spacer(1,4.5*cm))
        for l in lines:
            p = Paragraph(l,self.style)
            self.Story.append(p)
            self.Story.append(Spacer(1,0.2*cm))
        self.Story.append(PageBreak())
        print ".",

and this is what I do as static decoration of each page:

        canvas.saveState()
        x = cm
        y = A4[1] - cm * 3

        # print the header and signature
        canvas.drawImage(self.imhead, cm * 2,A4[1] - cm * 4.0, A4[0] - cm * 4, 
cm * 2.5)
        canvas.drawImage(self.imsign, A4[0] - cm * 9.5, cm*5.5, 130,35)

        #footer separation line
        canvas.line(x,cm*2.6,A4[0] - x,cm*2.6)

	# footer        
	w = canvas.stringWidth("some text",'Times-Roman',8)
        canvas.drawString((A4[0] - w) / 2,cm*line,"some text")

	w = canvas.stringWidth("some text",'Times-Roman',8)
        canvas.drawString((A4[0] - w) / 2,cm*line,"some text")


> I tried the following which seems to indicate no cycles. Even so I see
> the memory creeping up
>
> ################################
> from reportlab.lib.styles import ParagraphStyle
> from reportlab.platypus import *
> def main():
>         i = 0
>         story = []
>         for x in xrange(100,900):
>                 story.append(Paragraph(str(x),ParagraphStyle('normal')))
>                 story.append(PageBreak())
>                 if i % 100==0:
>                         fn = "test_%03d.pdf"%i
>                         SimpleDocTemplate(fn).build(story)
>                         print 'Build',fn
>                         story = []
>                 i += 1
>         if story:
>                 fn = "test_%03d.pdf"%i
>                 SimpleDocTemplate(fn).build(story)
>                 print 'Build',fn
>                 story = []
>
> if __name__=='__main__':
>         import Cyclops
>         z = Cyclops.CycleFinder()
>         z.run(main)
>         z.find_cycles(purge_dead_roots=0)
>         z.show_stats()
>         z.show_cycles()
> ################################
> And get
>
> C:\Tmp\ttt>t1.py
> Build test_000.pdf
> Build test_100.pdf
> Build test_200.pdf
> Build test_300.pdf
> Build test_400.pdf
> Build test_500.pdf
> Build test_600.pdf
> Build test_700.pdf
> Build test_800.pdf
> **********************************************************************
> # objects in root set: 20447
> # distinct structured objects reachable: 38529
> # distinct structured objects in cycles: 0
> # cycles found: 0
> # cycles filtered out: 0
> # strongly-connected components: 0
> # arcs examined: 183782
> **********************************************************************
> # all cycles:

-- 
Linux webmaster & sysadmin
pradu@pradu.it