def closure(): if zone: SFData.stackZone(zone); try: return self.func(*args, **kwargs) finally: if zone: if zone != SFData.unstackZone(): raise ValueError('Memory Zone mismatch')
def __call__(self,*args, **kwargs): # we need to make sure that all the futures in the current # context are completed before we schedule a new one or # we risk forming cycles. This might seem highly inefficient # but it does not work out that way due to the lazy execution system # # One might thing that just checking the args is enough but because # functions in python are closures, it is not enough! if SF_DO_STEALING: sf_parallel.recursive_get_futures(locals()) # If we are in a memory zone we must propogate that zone to the new thread # of execution. zone = SFData.peekZone() def closure(): if zone: SFData.stackZone(zone); try: return self.func(*args, **kwargs) finally: if zone: if zone != SFData.unstackZone(): raise ValueError('Memory Zone mismatch') c_log('Parallel',self.func,closure) if SF_PENDING.size()> SF_LINEAR_LIMIT or SF_LINEAR: return closure() else: return Sf_SuperFuture(closure)