comparison piecrust/processing/pipeline.py @ 442:171dde4f61dc

performance: Add profiling to the asset pipeline workers.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 28 Jun 2015 14:52:58 -0700
parents 6238dcfc7a78
children aefe70229fdd
comparison
equal deleted inserted replaced
441:dc8518c51cbe 442:171dde4f61dc
253 253
254 logger.debug("Queuing: %s" % path) 254 logger.debug("Queuing: %s" % path)
255 ctx.pool.queue.put_nowait(job) 255 ctx.pool.queue.put_nowait(job)
256 256
257 def _createWorkerPool(self): 257 def _createWorkerPool(self):
258 import sys
259
260 main_module = sys.modules['__main__']
261 is_profiling = os.path.basename(main_module.__file__) in [
262 'profile.py', 'cProfile.py']
263
258 pool = _WorkerPool() 264 pool = _WorkerPool()
259 for i in range(self.num_workers): 265 for i in range(self.num_workers):
260 ctx = ProcessingWorkerContext( 266 ctx = ProcessingWorkerContext(
261 self.app.root_dir, self.out_dir, self.tmp_dir, 267 self.app.root_dir, self.out_dir, self.tmp_dir,
262 pool.queue, pool.results, pool.abort_event, 268 pool.queue, pool.results, pool.abort_event,
263 self.force, self.app.debug) 269 self.force, self.app.debug)
270 ctx.is_profiling = is_profiling
264 ctx.enabled_processors = self.enabled_processors 271 ctx.enabled_processors = self.enabled_processors
265 ctx.additional_processors = self.additional_processors 272 ctx.additional_processors = self.additional_processors
266 w = multiprocessing.Process( 273 w = multiprocessing.Process(
267 name='PipelineWorker_%d' % i, 274 name='PipelineWorker_%d' % i,
268 target=worker_func, args=(i, ctx)) 275 target=worker_func, args=(i, ctx))