You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:32:55 UTC
[buildstream] 05/22: WIP: jobpickler, _{,un}reduce_plugincontext
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch aevri/win32_minimal_seemstowork_20190829
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit e9e61f34c9977b2004050de1b2fa108b6493e7c3
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Tue Jul 9 17:35:32 2019 +0100
WIP: jobpickler, _{,un}reduce_plugincontext
---
src/buildstream/_plugincontext.py | 13 -------------
src/buildstream/_scheduler/jobs/jobpickler.py | 24 ++++++++++++++++++++++++
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/buildstream/_plugincontext.py b/src/buildstream/_plugincontext.py
index 60d2475..c058c58 100644
--- a/src/buildstream/_plugincontext.py
+++ b/src/buildstream/_plugincontext.py
@@ -68,19 +68,6 @@ class PluginContext():
self._alternate_sources = {}
self._format_versions = format_versions
- def __getstate__(self):
- import copy
- state = copy.copy(self.__dict__)
- del state['_site_source']
- state['_types'] = {}
- return state
-
- def __setstate__(self, state):
- self.__dict__ = state
- self._site_source = self._plugin_base.make_plugin_source(
- searchpath=self._site_plugin_path,
- identifier='site_plugin-' + self._identifier)
-
# lookup():
#
# Fetches a type loaded from a plugin in this plugin context
diff --git a/src/buildstream/_scheduler/jobs/jobpickler.py b/src/buildstream/_scheduler/jobs/jobpickler.py
index 5c1742f..841037c 100644
--- a/src/buildstream/_scheduler/jobs/jobpickler.py
+++ b/src/buildstream/_scheduler/jobs/jobpickler.py
@@ -28,6 +28,7 @@ from ..._protos.buildstream.v2.artifact_pb2 import Artifact as ArtifactProto
from ... import Element, Source
from ..._loader import Loader
from ..._messenger import Messenger
+from ..._plugincontext import PluginContext
def _reduce_artifact_proto(instance):
@@ -53,6 +54,7 @@ def _reduce_loader(instance):
# time that seems just right is here, when preparing the child process'
# copy of the Loader.
#
+ # TODO: move this reduce func to loader.py
del state['_fetch_subprojects']
return (Loader.__new__, (Loader,), state)
@@ -72,11 +74,32 @@ def _reduce_messenger(instance):
# which removes and restores the _message_handler. This wouldn't require
# access to private details of Messenger.
#
+ # TODO: move this reduce func to messenger.py
del state['_message_handler']
return (Messenger.__new__, (Messenger,), state)
+def _reduce_plugincontext(instance):
+ assert isinstance(instance, PluginContext)
+ state = instance.__dict__.copy()
+ del state['_site_source']
+ state['_types'] = {}
+
+ # TODO: move this reduce func to plugincontext.py
+
+ return (_unreduce_plugincontext, (state,))
+
+
+def _unreduce_plugincontext(state):
+ instance = PluginContext()
+ instance.__dict__ = state
+ instance._site_source = instance._plugin_base.make_plugin_source(
+ searchpath=instance._site_plugin_path,
+ identifier='site_plugin-' + instance._identifier)
+ return instance
+
+
def _reduce_element(element):
assert isinstance(element, Element)
meta_kind = element._meta_kind
@@ -139,6 +162,7 @@ def pickle_child_job(child_job, context):
pickler.dispatch_table[ArtifactProto] = _reduce_artifact_proto
pickler.dispatch_table[Loader] = _reduce_loader
pickler.dispatch_table[Messenger] = _reduce_messenger
+ pickler.dispatch_table[PluginContext] = _reduce_plugincontext
pickler.dump(child_job)
data.seek(0)