comparison piecrust/data/provider.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 fd8e39254da0
children 32c7c2d219d2
comparison
equal deleted inserted replaced
410:d1a472464e57 411:e7b865f8f335
116 def _buildYearlyArchive(self): 116 def _buildYearlyArchive(self):
117 if self._yearly is not None: 117 if self._yearly is not None:
118 return self._yearly 118 return self._yearly
119 119
120 self._yearly = [] 120 self._yearly = []
121 yearly_index = {}
121 for post in self._source.getPages(): 122 for post in self._source.getPages():
122 year = post.datetime.strftime('%Y') 123 year = post.datetime.strftime('%Y')
123 124
124 posts_this_year = next( 125 posts_this_year = yearly_index.get(year)
125 filter(lambda y: y.name == year, self._yearly),
126 None)
127 if posts_this_year is None: 126 if posts_this_year is None:
128 timestamp = time.mktime( 127 timestamp = time.mktime(
129 (post.datetime.year, 1, 1, 0, 0, 0, 0, 0, -1)) 128 (post.datetime.year, 1, 1, 0, 0, 0, 0, 0, -1))
130 posts_this_year = BlogArchiveEntry(self._page, year, timestamp) 129 posts_this_year = BlogArchiveEntry(self._page, year, timestamp)
131 self._yearly.append(posts_this_year) 130 self._yearly.append(posts_this_year)
131 yearly_index[year] = posts_this_year
132 132
133 posts_this_year._data_source.append(post) 133 posts_this_year._data_source.append(post)
134 self._yearly = sorted(self._yearly, 134 self._yearly = sorted(self._yearly,
135 key=lambda e: e.timestamp, 135 key=lambda e: e.timestamp,
136 reverse=True) 136 reverse=True)