Mercurial > piecrust2
view piecrust/sources/array.py @ 411:e7b865f8f335
bake: Enable multiprocess baking.
Baking is now done by running a worker per CPU, and sending jobs to them.
This changes several things across the codebase:
* Ability to not cache things related to pages other than the 'main' page
(i.e. the page at the bottom of the execution stack).
* Decouple the baking process from the bake records, so only the main process
keeps track (and modifies) the bake record.
* Remove the need for 'batch page getters' and loading a page directly from
the page factories.
There are various smaller changes too included here, including support for
scope performance timers that are saved with the bake record and can be
printed out to the console. Yes I got carried away.
For testing, the in-memory 'mock' file-system doesn't work anymore, since
we're spawning processes, so this is replaced by a 'tmpfs' file-system which
is saved in temporary files on disk and deleted after tests have run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 12 Jun 2015 17:09:19 -0700 |
parents | f130365568ff |
children | ab5c6a8ae90a |
line wrap: on
line source
from piecrust.sources.base import PageSource from piecrust.sources.mixins import SimplePaginationSourceMixin from piecrust.sources.pageref import PageRef class CachedPageFactory(object): """ A `PageFactory` (in appearance) that already has a page built. """ def __init__(self, page): self._page = page @property def rel_path(self): return self._page.rel_path @property def metadata(self): return self._page.source_metadata @property def ref_spec(self): return self._page.ref_spec @property def path(self): return self._page.path def buildPage(self): return self._page class ArraySource(PageSource, SimplePaginationSourceMixin): def __init__(self, app, inner_source, name='array', config=None): super(ArraySource, self).__init__(app, name, config) self.inner_source = inner_source @property def page_count(self): return len(self.inner_source) def getPageFactories(self): for p in self.inner_source: yield CachedPageFactory(p) def getTaxonomyPageRef(self, tax_name): return None