[erlang-questions] spawning funs on other nodes that does not contain my module

Ali Yakout <>
Wed Dec 1 16:30:05 CET 2010


Hi,

There is a shell function that does the same.

1> nl(my_mod)
abcast
2>


%% Network version of l/1
nl(Mod) ->
    case code:get_object_code(Mod) of
	{_Module, Bin, Fname} ->
            rpc:eval_everywhere(code,load_binary,[Mod,Fname,Bin]);
	Other ->
	    Other
    end. 


-Ali

-----Original Message-----
From:  [mailto:] On Behalf Of Mazen Harake
Sent: Wednesday, December 01, 2010 12:00 AM
Cc: Marcel Meyer; erlang-questions
Subject: Re: [erlang-questions] spawning funs on other nodes that does not contain my module

This is how I do it (taken from: 
https://github.com/mazenharake/entop/blob/master/src/entop_view.erl#L59)

remote_load_code(Module, Node) ->
{_, Binary, Filename} = code:get_object_code(Module), rpc:call(Node, code, load_binary, [Module, Filename, Binary]). /M



On 30/11/2010 22:31, Lukas Larsson wrote:
> It is not possible directly, you would have to get the code to the 
> other side somehow. code:load_binary is made specifically for this 
> purpose,
>
> http://erlang.org/doc/man/code.html#load_binary-3
>
> Just use rpc:call(MyNode,
> code,load_binary,[mymod,"mymod.erl",BinaryModuleCode]) and off you go!
>
> Lukas
>
> On Tue, Nov 30, 2010 at 7:36 PM, Marcel Meyer<>wrote:
>
>> Hi there,
>>
>> Is it possible to spawn a function (which is pretty straight forward, 
>> essentially a receive loop that grabs the message and 
>> file:write_file's it to the file system) on another node, which does 
>> not have a copy of my module?
>>
>> I thought I would be able to make a fun that returns the mentioned 
>> fun above and then spawn that message sink on another node.
>>
>> I am investigating writing a file propagation system and it would be 
>> nice if there is one process that gets notified of new files, which 
>> spawns a fun on each recipient node, which tells that node how to 
>> handle it.
>>
>> Any insights? Or should each node be running a file sink that just 
>> listens for these {save, Data} msgs? I am trying to write something 
>> where I dont have to manage the child nodes and their code. Perhaps a 
>> file sink gen_server on each node that supports upgrades?
>>
>> Regards,
>> Marcel
>>



More information about the erlang-questions mailing list