1
GENERATING IN MULTIPROCESSING
2
=============================
4
This is exactly the same report we made for "without-Django" test. But this is going
5
to be ran under an independent Process, from multiprocessing library.
7
Is important to keep aware on:
9
- multiprocessing works on Python 2.3 or higher - and is a builtin package on 2.6
10
- you must use 'generate_under_process_by' instead of 'generate_by'
11
- you can do it without 'generate_under_process_by', using geraldo.utils.run_under_process
12
decorator, if you prefer do it manually
13
- the method ''generate_under_process_by' is not the best solution ever. You must keep
14
aware on what kind of report generation you are doing, and how server is configure, but
15
most of cases will work well
16
- the decorator 'run_under_process' will work only if geraldo.utils.DISABLE_MULTIPROCESSING
20
>>> cur_dir = os.path.dirname(os.path.abspath(__file__))
22
>>> from geraldo.utils import A4, cm, TA_CENTER, TA_RIGHT
24
>>> from geraldo import Report, ReportBand, Label, ObjectValue, SystemField,\
25
... FIELD_ACTION_COUNT, BAND_WIDTH
29
>>> class SimpleListReport(Report):
30
... title = 'Demonstration without Django'
32
... class band_page_header(ReportBand):
35
... SystemField(expression='%(report_title)s', top=0.1*cm, left=0, width=BAND_WIDTH,
36
... style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
37
... Label(text="ID", top=0.8*cm, left=0),
38
... Label(text="Name", top=0.8*cm, left=3*cm),
40
... borders = {'bottom': True}
42
... class band_page_footer(ReportBand):
45
... Label(text='Created with Geraldo Reports', top=0.1*cm, left=0),
46
... SystemField(expression='Page # %(page_number)d of %(page_count)d', top=0.1*cm,
47
... width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
49
... borders = {'top': True}
51
... class band_detail(ReportBand):
54
... ObjectValue(attribute_name='id', top=0, left=0),
55
... ObjectValue(attribute_name='name', top=0, left=3*cm),
58
>>> class MyObject(object):
59
... def __init__(self, **kwargs):
60
... for k,v in kwargs.items():
61
... setattr(self, k, v)
65
... MyObject(id=1, name='Rio de Janeiro'),
66
... MyObject(id=2, name='New York'),
67
... MyObject(id=3, name='Paris'),
68
... MyObject(id=4, name='London'),
69
... MyObject(id=5, name='Tokyo'),
70
... MyObject(id=6, name='Moscow'),
71
... MyObject(id=7, name='Beijing'),
72
... MyObject(id=8, name='Hamburg'),
73
... MyObject(id=9, name='New Delhi'),
74
... MyObject(id=10, name='Jakarta'),
77
>>> report = SimpleListReport(queryset=objects_list)
81
>>> from geraldo.generators import PDFGenerator
83
>>> report.generate_under_process_by(PDFGenerator, filename=os.path.join(cur_dir, 'output/generated-in-multiprocessing.pdf'))