From 0abcf46c56a6886c99fea0538a5d198679fcbe99 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Tue, 8 Mar 2016 14:28:23 -0800 Subject: [PATCH] store objects in objstore --- lib/orchpy/orchpy/worker.pyx | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/orchpy/orchpy/worker.pyx b/lib/orchpy/orchpy/worker.pyx index 7895f1c56..d7633bbbe 100644 --- a/lib/orchpy/orchpy/worker.pyx +++ b/lib/orchpy/orchpy/worker.pyx @@ -294,15 +294,18 @@ cdef class Worker: while True: name, args, returnrefs = self.wait_for_next_task() print "got returnref", returnrefs - self.functions[name].executor(args, returnrefs) - # self.invoke_function(name, args) - + result = self.functions[name].executor(args, returnrefs) + if len(returnrefs) == 1: + self.put_obj(returnrefs[0], result) + else: + for i in range(len(returnrefs)): + self.put_obj(returnrefs[i], result[i]) global_worker = Worker() -def distributed(types, return_type, worker=global_worker): +def distributed(types, return_types, worker=global_worker): def distributed_decorator(func): - # deserialize arguments, execute function and serialize result + # deserialize arguments, execute function and return results def func_executor(args, returnrefs): arguments = [] for (i, arg) in enumerate(args): @@ -323,16 +326,10 @@ def distributed(types, return_type, worker=global_worker): # buf = bytearray() print "called with arguments", arguments result = func(*arguments) - # if unison.unison_type(result) != return_type: - # raise Exception("Return type of " + func.func_name + " does not match the return type specified in the @distributed decorator, was expecting " + str(return_type) + " but received " + str(unison.unison_type(result))) - # unison.serialize(buf, result) - # return memoryview(buf).tobytes() - # return result - # obj = ObjWrapper() - # serialize_into_2(result, obj.get_value()) - # print "put was sucessful? seems like so" - for i in range(len(returnrefs)): - worker.put_obj(returnrefs[i], result[i]) + # check number of return values and return types + if len(return_types) != 1 and len(result) != len(return_types): + raise Exception("The @distributed decorator for function " + func.__name__ + " has " + str(len(return_types)) + " return values with types " + str(return_types) + " but " + func.__name__ + " returned " + str(len(result)) + " values.") + return result # for remotely executing the function def func_call(*args, typecheck=False): return worker.call(func_call.func_name, func_call.module_name, args)