[erlang-questions] processes spawned on remote nodes don't run

Khitai Pang khitai.pang@REDACTED
Tue Dec 6 11:35:23 CET 2016


Hi Adrian,

Thank you for the information but unfortunately it's not the cause of my problem.  If I add 'user' io:format():

(myapp@REDACTED)6> run_on_all_nodes().
[<27616.12396.0>,<27612.19603.39>,<27615.48.51>]

(myapp@REDACTED)7> [spawn(Node, fun() -> io:format(user, "This runs on ~p~n", [node()]) end) || Node <- nodes()].
[<27616.12397.0>,<27612.19600.39>,<27615.77.51>]

(myapp@REDACTED)8> [spawn(Node, fun() -> io:format("This runs on ~p~n", [node()]) end) || Node <- nodes()].
This runs on myapp@REDACTED
This runs on rabbit@REDACTED
This runs on rabbit@REDACTED
[<27616.12398.0>,<27612.19631.39>,<27615.89.51>]

It doesn't seem to be I/O channeling problem, it seems that the spawned processes just don't run...


Thanks
khitai

On 2016/12/6 17:52, Adrian Roe wrote:
This confused me for a while as well…

To quote http://erlang.org/doc/man/erlang.html


group_leader() -> pid()


Returns the process identifier of the group leader for the process evaluating the function.

Every process is a member of some process group and all groups have a group leader. All I/O from the group is channeled to the group leader. When a new process is spawned, it gets the same group leader as the spawning process. Initially, at system startup, init is both its own group leader and the group leader of all processes.

There’s a helpful post here <http://erlang.org/pipermail/erlang-questions/2008-April/034573.html> http://erlang.org/pipermail/erlang-questions/2008-April/034573.html that talks about exactly what you are seeing.

If you change the
io:format("This runs on ~p~n", [node()])
to
io:format(user, "This runs on ~p~n", [node()])

I strongly suspect you will see the output you were expecting…

Adrian

On 6 Dec 2016, at 09:34, Khitai Pang <<mailto:khitai.pang@REDACTED>khitai.pang@REDACTED<mailto:khitai.pang@REDACTED>> wrote:

Hi,

I have the following function in user_default.erl:

run_on_all_nodes() ->
    [spawn(Node, fun() ->
                         io:format("This runs on ~p~n", [node()])
                 end) || Node <- nodes()].

When I run this function, processes can be spawned on remote nodes but
it seems that they don't run:

(myapp@REDACTED)1> nodes().
[myapp@REDACTED,rabbit@REDACTED,rabbit@REDACTED]

(myapp@REDACTED)2> run_on_all_nodes().
[<27616.12336.0>,<27612.15341.39>,<27615.22399.50>]

If I manually run the spawn command in the attached shell, it all works
fine:

(myapp@REDACTED)3> [spawn(Node, fun() -> io:format("This runs on ~p~n",
[node()]) end) || Node <- nodes()].
This runs on myapp@REDACTED
This runs on rabbit@REDACTED
This runs on rabbit@REDACTED
[<27616.12339.0>,<27612.15569.39>,<27615.22640.50>]


Any idea?


Thanks
Khitai
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED<mailto:erlang-questions@REDACTED>
http://erlang.org/mailman/listinfo/erlang-questions


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161206/e36afff9/attachment.htm>


More information about the erlang-questions mailing list