Ejemplo n.º 1
0
    def func_call(self, msg):

        func_data = msg[1]
        args = msg[2]
        kwargs = msg[3]
        nonce, context_key = msg[4]
        autoproxyize = msg[5]

        module = import_module('__main__')
        module.proxyize.set_state(nonce)

        args, kwargs = arg_kwarg_proxy_converter(args, kwargs)

        new_func_globals = module.__dict__  # add proper proxyize, context_key
        new_func_globals.update({
            'proxyize': module.proxyize,
            'context_key': context_key
        })

        new_func = types.FunctionType(func_data[0], new_func_globals,
                                      func_data[1], func_data[2], func_data[3])

        res = new_func(*args, **kwargs)
        if autoproxyize and isinstance(res, LocalArray):
            res = module.proxyize(res)
        Engine.INTERCOMM.send(res, dest=self.client_rank)
Ejemplo n.º 2
0
    def builtin_call(self, msg):
        func = msg[1]
        args = msg[2]
        kwargs = msg[3]

        args, kwargs = arg_kwarg_proxy_converter(args, kwargs)

        res = func(*args, **kwargs)
        Engine.INTERCOMM.send(res, dest=self.client_rank)
Ejemplo n.º 3
0
    def builtin_call(self, msg):
        func = msg[1]
        args = msg[2]
        kwargs = msg[3]

        args, kwargs = arg_kwarg_proxy_converter(args, kwargs)

        res = func(*args, **kwargs)
        Engine.INTERCOMM.send(res, dest=self.client_rank)
Ejemplo n.º 4
0
        def func_wrapper(func, apply_nonce, context_key, args, kwargs,
                         autoproxyize):
            """
            Function which calls the applied function after grabbing all the
            arguments on the engines that are passed in as names of the form
            `__distarray__<some uuid>`.
            """
            from importlib import import_module
            import types
            from distarray.metadata_utils import arg_kwarg_proxy_converter
            from distarray.localapi import LocalArray

            main = import_module('__main__')
            main.proxyize.set_state(apply_nonce)

            # Modify func to change the namespace it executes in.
            # but builtins don't have __code__, __globals__, etc.
            if not isinstance(func, types.BuiltinFunctionType):
                # get func's building  blocks first
                func_code = func.__code__
                func_name = func.__name__
                func_defaults = func.__defaults__
                func_closure = func.__closure__

                # build the func's new execution environment
                main.__dict__.update({'context_key': context_key})
                new_func_globals = main.__dict__
                # create the new func
                func = types.FunctionType(func_code, new_func_globals,
                                          func_name, func_defaults,
                                          func_closure)

            args, kwargs = arg_kwarg_proxy_converter(args, kwargs)
            result = func(*args, **kwargs)

            if autoproxyize and isinstance(result, LocalArray):
                return main.proxyize(result)
            else:
                return result
Ejemplo n.º 5
0
        def func_wrapper(func, apply_nonce, context_key, args, kwargs, autoproxyize):
            """
            Function which calls the applied function after grabbing all the
            arguments on the engines that are passed in as names of the form
            `__distarray__<some uuid>`.
            """
            from importlib import import_module
            import types
            from distarray.metadata_utils import arg_kwarg_proxy_converter
            from distarray.localapi import LocalArray

            main = import_module('__main__')
            main.proxyize.set_state(apply_nonce)

            # Modify func to change the namespace it executes in.
            # but builtins don't have __code__, __globals__, etc.
            if not isinstance(func, types.BuiltinFunctionType):
                # get func's building  blocks first
                func_code = func.__code__
                func_name = func.__name__
                func_defaults = func.__defaults__
                func_closure = func.__closure__

                # build the func's new execution environment
                main.__dict__.update({'context_key': context_key})
                new_func_globals = main.__dict__
                # create the new func
                func = types.FunctionType(func_code, new_func_globals,
                                          func_name, func_defaults,
                                          func_closure)

            args, kwargs = arg_kwarg_proxy_converter(args, kwargs)
            result = func(*args, **kwargs)

            if autoproxyize and isinstance(result, LocalArray):
                return main.proxyize(result)
            else:
                return result
Ejemplo n.º 6
0
    def func_call(self, msg):

        func_data = msg[1]
        args = msg[2]
        kwargs = msg[3]
        nonce, context_key = msg[4]
        autoproxyize = msg[5]

        module = import_module('__main__')
        module.proxyize.set_state(nonce)

        args, kwargs = arg_kwarg_proxy_converter(args, kwargs)

        new_func_globals = module.__dict__  # add proper proxyize, context_key
        new_func_globals.update({'proxyize': module.proxyize,
                                'context_key': context_key})

        new_func = types.FunctionType(func_data[0], new_func_globals,
                                      func_data[1], func_data[2], func_data[3])

        res = new_func(*args, **kwargs)
        if autoproxyize and isinstance(res, LocalArray):
            res = module.proxyize(res)
        Engine.INTERCOMM.send(res, dest=self.client_rank)