Mercurial > piecrust2
diff piecrust/processing/pipeline.py @ 492:d90ccdf18156
tests: Fix processing tests on Windows.
See the comment in `pipeline.py` for more info but basically I was passing
already initialized processors to the worker pool, which means pickling the
whole app. Pretty bad. Interesting that it only broke on Windows, though.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 23 Jul 2015 22:07:32 -0700 |
parents | aefe70229fdd |
children | 7453baeb0839 |
line wrap: on
line diff
--- a/piecrust/processing/pipeline.py Wed Jul 22 22:21:42 2015 -0700 +++ b/piecrust/processing/pipeline.py Thu Jul 23 22:07:32 2015 -0700 @@ -57,8 +57,15 @@ self.force_patterns = make_re(baker_params.get('force', [])) # Those things are mostly for unit-testing. + # + # Note that additiona processors can't be passed as instances. + # Instead, we need some factory functions because we need to create + # one instance right away to use during the initialization phase, and + # another instance to pass to the worker pool. The initialized one will + # be tied to the PieCrust app instance, which can't be pickled across + # processes. self.enabled_processors = None - self.additional_processors = None + self.additional_processors_factories = None def addIgnorePatterns(self, patterns): self.ignore_patterns += make_re(patterns) @@ -74,10 +81,11 @@ self.enabled_processors) processors = get_filtered_processors(processors, self.enabled_processors) - if self.additional_processors is not None: + if self.additional_processors_factories is not None: logger.debug("Adding %s additional processors." % - len(self.additional_processors)) - for proc in self.additional_processors: + len(self.additional_processors_factories)) + for proc_fac in self.additional_processors_factories: + proc = proc_fac() self.app.env.registerTimer(proc.__class__.__name__, raise_if_registered=False) proc.initialize(self.app) @@ -248,7 +256,10 @@ self.app.root_dir, self.out_dir, self.tmp_dir, self.force, self.app.debug) ctx.enabled_processors = self.enabled_processors - ctx.additional_processors = self.additional_processors + if self.additional_processors_factories is not None: + ctx.additional_processors = [ + proc_fac() + for proc_fac in self.additional_processors_factories] pool = WorkerPool( worker_class=ProcessingWorker,