From b70b5db9d8c7f4291dfdb80fe55b28c494a2e442 2013-03-21 20:51:46 From: MinRK Date: 2013-03-21 20:51:46 Subject: [PATCH] use canning hook in dependent allows the dependency function to be called even before the real task arguments are unpacked. --- diff --git a/IPython/parallel/controller/dependency.py b/IPython/parallel/controller/dependency.py index a5b1dfe..02ee8fa 100644 --- a/IPython/parallel/controller/dependency.py +++ b/IPython/parallel/controller/dependency.py @@ -59,10 +59,12 @@ class dependent(object): self.df = df self.dargs = dargs self.dkwargs = dkwargs - - def __call__(self, *args, **kwargs): + + def check_dependency(self): if self.df(*self.dargs, **self.dkwargs) is False: raise UnmetDependency() + + def __call__(self, *args, **kwargs): return self.f(*args, **kwargs) if not py3compat.PY3: diff --git a/IPython/utils/pickleutil.py b/IPython/utils/pickleutil.py index bfff04c..a19c1c9 100644 --- a/IPython/utils/pickleutil.py +++ b/IPython/utils/pickleutil.py @@ -64,7 +64,7 @@ class CannedObject(object): obj = self.obj for key in self.keys: setattr(obj, key, uncan(getattr(obj, key), g)) - + if self.hook: self.hook = uncan(self.hook, g) self.hook(obj, g) @@ -308,6 +308,11 @@ def uncan_sequence(obj, g=None): else: return obj +def _uncan_dependent_hook(dep, g=None): + dep.check_dependency() + +def can_dependent(obj): + return CannedObject(obj, keys=('f', 'df'), hook=_uncan_dependent_hook) #------------------------------------------------------------------------------- # API dictionaries @@ -316,7 +321,7 @@ def uncan_sequence(obj, g=None): # These dicts can be extended for custom serialization of new objects can_map = { - 'IPython.parallel.dependent' : lambda obj: CannedObject(obj, keys=('f','df')), + 'IPython.parallel.dependent' : can_dependent, 'numpy.ndarray' : CannedArray, FunctionType : CannedFunction, bytes : CannedBytes,