comparison piecrust/sources/base.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 4b1019bb2533
children 32c7c2d219d2
comparison
equal deleted inserted replaced
410:d1a472464e57 411:e7b865f8f335
18 18
19 logger = logging.getLogger(__name__) 19 logger = logging.getLogger(__name__)
20 20
21 21
22 def build_pages(app, factories): 22 def build_pages(app, factories):
23 with app.env.page_repository.startBatchGet(): 23 for f in factories:
24 for f in factories: 24 yield f.buildPage()
25 yield f.buildPage()
26 25
27 26
28 class InvalidFileSystemEndpointError(Exception): 27 class InvalidFileSystemEndpointError(Exception):
29 def __init__(self, source_name, fs_endpoint): 28 def __init__(self, source_name, fs_endpoint):
30 super(InvalidFileSystemEndpointError, self).__init__( 29 super(InvalidFileSystemEndpointError, self).__init__(
57 return self._doBuildPage() 56 return self._doBuildPage()
58 57
59 def _doBuildPage(self): 58 def _doBuildPage(self):
60 logger.debug("Building page: %s" % self.path) 59 logger.debug("Building page: %s" % self.path)
61 page = Page(self.source, copy.deepcopy(self.metadata), self.rel_path) 60 page = Page(self.source, copy.deepcopy(self.metadata), self.rel_path)
62 # Load it right away, especially when using the page repository,
63 # because we'll be inside a critical scope.
64 page._load()
65 return page 61 return page
66 62
67 63
68 class PageSource(object): 64 class PageSource(object):
69 """ A source for pages, e.g. a directory with one file per page. 65 """ A source for pages, e.g. a directory with one file per page.