[erlang-questions] Question re console io in a distributed computation

Ulf Wiger <>
Fri Oct 31 00:13:39 CET 2008


Whether there's a bug hidden in this, I'm not sure... but certainly some
interesting interaction, and if it's documented anywhere, I have yet to
find it. (:

If you start erlang on the remote nodes using -noshell, it works as expected.
Otherwise, it seems as if the shell steals all the input and starves the
call to io:get_line() (or whichever input function you use). This starvation is
certainly unexpected, since the output (the prompt) appears on the console,
but the input request is never served.

Calling io:get_line(Prompt) locally from the shell works, presumably because
the shell is not consuming input while waiting for the shell evaluator
to return.

BR,
Ulf W

2008/10/30 David Cabana <>:
> "Very interesting...", you say. Does that mean you were you able to
> reproduce what I encountered?
>
> I'm a relative newcomer to Erlang, so I am far more inclined to believe I'm
> doing something wrong than to believe I've run into a bug. But if you're
> running into the same problem, I begin to suspect I'm out of my league. Any
> thoughts on what's going on?
>
> BTW, I'm running R12B-3 on Ubuntu Hardy.
>
> On Wed, Oct 29, 2008 at 4:13 PM, Ulf Wiger <> wrote:
>>
>> Hmm, sorry, I was too fast there. The prompt appeared all right,
>> but the call never returned. Very interesting...
>>
>> BR,
>> Ulf W
>>
>> 2008/10/29 Ulf Wiger <>:
>> > Well, I'm not quite sure why it didn't work with the group leader
>> > (I'd have to dig into that), but the 'user' trick ought to work with
>> > the question as well. Compare:
>> >
>> > rpc:call(OtherNode, io, get_line, ["Hello? "])
>> >
>> > with
>> >
>> > rpc:call(OtherNode, io, get_line, [user, "Hello? "]).
>> >
>> > The first version should give a prompt on the originating node,
>> > and the second version should give it on the target node
>> > (assuming, of course, that the target node has a shell.)
>> >
>> > BR,
>> > Ulf W
>> >
>> > 2008/10/29 David Cabana <>:
>> >> I've now played with both of  Ulf's suggested approaches  (using
>> >> io:format(user, Fmt, Args), or alternatively, resetting processes group
>> >> leaders) and have gotten output to go the correct consoles with both
>> >> approaches.  Which of course led to the next hurdle,  reading input
>> >> from the
>> >> player console.
>> >>
>> >> The referee sent a question to the player, which was written to the
>> >> player
>> >> node's console. What I want to do is type a response in the player
>> >> console,
>> >> have it read, parsed, and sent to the referee, but so far no luck. My
>> >> responses vanish into the ether, and the referee hangs waiting for
>> >> players
>> >> to respond.
>> >>
>> >> Here is how I am trying to respond. When the player process receives a
>> >> question, it writes to the console and tries to read a line:
>> >>
>> >> <when I have reset player group leaders>
>> >>     io:fwrite("~n~s", [Question]),
>> >>     Reply = io:get_line(["= "]),
>> >>
>> >> <did not mess with group leaders, instead specified the 'user' atom
>> >> during
>> >> io>
>> >> I have also tried:
>> >>     io:fwrite(user, "~n~s", [Question]),
>> >>     Reply = io:get_line(user, ["= "]),
>> >>
>> >>
>> >> It occurs to me that maybe I am going about this the wrong way? Perhaps
>> >> my
>> >> approch is misconceived.  I have to believe that console IO in a
>> >> client-server setting is pretty common. Can anyone point me in the
>> >> right
>> >> direction?
>> >>
>> >> Thank you,
>> >> David
>> >>>
>> >>> On Fri, Oct 24, 2008 at 2:44 PM, Ulf Wiger (TN/EAB)
>> >>> <> wrote:
>> >>>>
>> >>>> David Cabana skrev:
>> >>>> >
>> >>>>>
>> >>>>> The messages flow correctly, but all the terminal io happens in
>> >>>>> a single console, the one associated with the referee node.
>> >>>>>
>> >>>>> My question is how to get player output written to the console of
>> >>>>> the
>> >>>>> corresponding
>> >>>>> player node?
>> >>>>
>> >>>> Use io:format(user, Fmt, Args)
>> >>>>
>> >>>> Alternatively, set the group leader of the process to some
>> >>>> local process - e.g. the group leader of net_kernel
>> >>>> (found by calling process_info(whereis(net_kernel),group_leader)).
>> >>>>
>> >>>> The group leader is the process that's handed all io messages.
>> >>>> The rpc server deliberately sets the group leader of an rpc
>> >>>> handler process to that of the caller on the originating node,
>> >>>> since the remote node may not always have a tty to print to.
>> >>>> When spawning, the group leader of the spawned process will
>> >>>> be inherited from the parent. If you spawn a process on
>> >>>> another node, it will still have the same group leader as
>> >>>> the parent.
>> >>>>
>> >>>> The BIF group_leader(Pid,New_group_leader_pid) sets a new
>> >>>> leader.
>> >>>>
>> >>>> BR,
>> >>>> Ulf W
>> >>>
>> >>
>> >>
>> >> _______________________________________________
>> >> erlang-questions mailing list
>> >> 
>> >> http://www.erlang.org/mailman/listinfo/erlang-questions
>> >>
>> >
>
>



More information about the erlang-questions mailing list