comparison piecrust/chefutil.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 a561fbad0b7f
children 0e9a94b7fdfa
comparison
equal deleted inserted replaced
410:d1a472464e57 411:e7b865f8f335
1 import time 1 import time
2 import logging
3 import contextlib
2 from colorama import Fore 4 from colorama import Fore
3 5
4 6
7 @contextlib.contextmanager
8 def format_timed_scope(logger, message, *, level=logging.INFO, colored=True):
9 start_time = time.perf_counter()
10 yield
11 logger.log(level, format_timed(start_time, message, colored=colored))
12
13
5 def format_timed(start_time, message, indent_level=0, colored=True): 14 def format_timed(start_time, message, indent_level=0, colored=True):
6 end_time = time.clock() 15 end_time = time.perf_counter()
7 indent = indent_level * ' ' 16 indent = indent_level * ' '
8 time_str = '%8.1f ms' % ((end_time - start_time) * 1000.0) 17 time_str = '%8.1f ms' % ((end_time - start_time) * 1000.0)
9 if colored: 18 if colored:
10 return '[%s%s%s] %s' % (Fore.GREEN, time_str, Fore.RESET, message) 19 return '[%s%s%s] %s' % (Fore.GREEN, time_str, Fore.RESET, message)
11 return '%s[%s] %s' % (indent, time_str, message) 20 return '%s[%s] %s' % (indent, time_str, message)