diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-06-27 14:04:52 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-24 12:27:10 +0000 |
commit | ab3b89f1fe412afea6daed5cf5a5a9703c4db09d (patch) | |
tree | 2bb42e2e30de3072901e499cb1bb5c3ec5e1fc0a /src/buildstream/_options | |
parent | da2f04daf39963aaa6bc6c9385c80574395d8aeb (diff) | |
download | buildstream-ab3b89f1fe412afea6daed5cf5a5a9703c4db09d.tar.gz |
optionpool: make OptionPool picklable
In order to enable the 'spawn' method of creating jobs, make sure that
OptionPool is pickable, otherwise it cannot be sent to the job process.
Diffstat (limited to 'src/buildstream/_options')
-rw-r--r-- | src/buildstream/_options/optionpool.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/buildstream/_options/optionpool.py b/src/buildstream/_options/optionpool.py index efafdcdce..d6b1b1614 100644 --- a/src/buildstream/_options/optionpool.py +++ b/src/buildstream/_options/optionpool.py @@ -52,9 +52,19 @@ class OptionPool(): self._options = {} # The Options self._variables = None # The Options resolved into typed variables - # jinja2 environment, with default globals cleared out of the way - self._environment = jinja2.Environment(undefined=jinja2.StrictUndefined) - self._environment.globals = [] + self._environment = None + self._init_environment() + + def __getstate__(self): + state = self.__dict__.copy() + # Jinja2 Environments don't appear to be serializable. It is easy + # enough for us to reconstruct this one anyway, so no need to pickle it. + del state['_environment'] + return state + + def __setstate__(self, state): + self.__dict__.update(state) + self._init_environment() # load() # @@ -287,3 +297,8 @@ class OptionPool(): return True return False + + def _init_environment(self): + # jinja2 environment, with default globals cleared out of the way + self._environment = jinja2.Environment(undefined=jinja2.StrictUndefined) + self._environment.globals = [] |