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

Mazen Harake <>
Tue Nov 30 23:00:05 CET 2010


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