comparison piecrust/app.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 c2ca72fb7f0b
children 0e9a94b7fdfa
comparison
equal deleted inserted replaced
410:d1a472464e57 411:e7b865f8f335
1 import re 1 import re
2 import json 2 import json
3 import time
3 import os.path 4 import os.path
4 import codecs 5 import codecs
5 import hashlib 6 import hashlib
6 import logging 7 import logging
7 import collections 8 import collections
411 self.env = env 412 self.env = env
412 if self.env is None: 413 if self.env is None:
413 self.env = StandardEnvironment() 414 self.env = StandardEnvironment()
414 self.env.initialize(self) 415 self.env.initialize(self)
415 416
417 self.env.registerTimer('SiteConfigLoad')
418 self.env.registerTimer('PageLoad')
419 for engine in self.plugin_loader.getTemplateEngines():
420 self.env.registerTimer(engine.__class__.__name__)
421 for fmt in self.plugin_loader.getFormatters():
422 self.env.registerTimer(fmt.__class__.__name__)
423
416 @cached_property 424 @cached_property
417 def config(self): 425 def config(self):
418 logger.debug("Creating site configuration...") 426 logger.debug("Creating site configuration...")
427 start_time = time.perf_counter()
428
419 paths = [] 429 paths = []
420 if self.theme_dir: 430 if self.theme_dir:
421 paths.append(os.path.join(self.theme_dir, THEME_CONFIG_PATH)) 431 paths.append(os.path.join(self.theme_dir, THEME_CONFIG_PATH))
422 paths.append(os.path.join(self.root_dir, CONFIG_PATH)) 432 paths.append(os.path.join(self.root_dir, CONFIG_PATH))
423 433
454 if srcc is not None: 464 if srcc is not None:
455 for sn, sc in srcc.items(): 465 for sn, sc in srcc.items():
456 sc['realm'] = REALM_THEME 466 sc['realm'] = REALM_THEME
457 config.fixups.append(_fixupThemeSources) 467 config.fixups.append(_fixupThemeSources)
458 468
469 self.env.stepTimer('SiteConfigLoad', time.perf_counter() - start_time)
459 return config 470 return config
460 471
461 @cached_property 472 @cached_property
462 def assets_dirs(self): 473 def assets_dirs(self):
463 assets_dirs = self._get_configurable_dirs(ASSETS_DIR, 474 assets_dirs = self._get_configurable_dirs(ASSETS_DIR,