Mercurial > piecrust2
comparison piecrust/baking/worker.py @ 702:c62d83e17abf
bake: Some more optimizations.
Write the output files in a background thread to get away from the GIL.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 16 Apr 2016 22:50:07 -0700 |
parents | 3bc9f857eb48 |
children | ab5c6a8ae90a |
comparison
equal
deleted
inserted
replaced
701:066d6156525c | 702:c62d83e17abf |
---|---|
79 data.timers.update(pool_reports) | 79 data.timers.update(pool_reports) |
80 return { | 80 return { |
81 'type': 'stats', | 81 'type': 'stats', |
82 'data': data} | 82 'data': data} |
83 | 83 |
84 def shutdown(self): | |
85 for jh in self.job_handlers.values(): | |
86 jh.shutdown() | |
87 | |
84 | 88 |
85 JOB_LOAD, JOB_RENDER_FIRST, JOB_BAKE = range(0, 3) | 89 JOB_LOAD, JOB_RENDER_FIRST, JOB_BAKE = range(0, 3) |
86 | 90 |
87 | 91 |
88 class JobHandler(object): | 92 class JobHandler(object): |
93 def app(self): | 97 def app(self): |
94 return self.ctx.app | 98 return self.ctx.app |
95 | 99 |
96 def handleJob(self, job): | 100 def handleJob(self, job): |
97 raise NotImplementedError() | 101 raise NotImplementedError() |
102 | |
103 def shutdown(self): | |
104 pass | |
98 | 105 |
99 | 106 |
100 def _get_errors(ex): | 107 def _get_errors(ex): |
101 errors = [] | 108 errors = [] |
102 while ex is not None: | 109 while ex is not None: |
181 class BakeJobHandler(JobHandler): | 188 class BakeJobHandler(JobHandler): |
182 def __init__(self, ctx): | 189 def __init__(self, ctx): |
183 super(BakeJobHandler, self).__init__(ctx) | 190 super(BakeJobHandler, self).__init__(ctx) |
184 self.page_baker = PageBaker(ctx.app, ctx.out_dir, ctx.force) | 191 self.page_baker = PageBaker(ctx.app, ctx.out_dir, ctx.force) |
185 | 192 |
193 def shutdown(self): | |
194 self.page_baker.shutdown() | |
195 | |
186 def handleJob(self, job): | 196 def handleJob(self, job): |
187 # Actually bake the page and all its sub-pages to the output folder. | 197 # Actually bake the page and all its sub-pages to the output folder. |
188 fac = load_factory(self.app, job['factory_info']) | 198 fac = load_factory(self.app, job['factory_info']) |
189 self.app.env.addManifestEntry('BakeJobs', fac.ref_spec) | 199 self.app.env.addManifestEntry('BakeJobs', fac.ref_spec) |
190 | 200 |