IEx interactive prompt mixed with IO.puts output and Application auto-start

While debugging applications and investigating execution data, it is annoying when other processes mixes output with the IEx prompt in the Linux terminal.

This is the testing scenario:

  1. Construct a process that prints random lines on the standard output using IO.puts/1 (you will get same effect using Logger with default configurations).
  2. Create a MyApplication and from start/2 launch your process.
  3. Add the usual [mod: {MyApplication, []}] in mix.exs to auto-start the application.

Result: the output from the background process will get mixed with the IEx prompt when you call iex -S mix.

Now, remove the [mod: {MyApplication, []}] from mix.exs. Start the interactive interpreter iex -S mix and start you application manually calling MyApplication.start(nil, nil). You will notice that the background process output will play nicely with the IEx prompt, leaving room for the user to enter code and other outputs never get mixed with the prompt.

I noticed this behavior while exercising Horde for a bigger project. This is the testing code: https://github.com/balena/elixir-party. Basically I left the Party.Application to be manually started from IEx prompt, so I could investigate variables and obtain all the information I needed about the cluster scenario in question. But before that I attempted to start the Party.Application directly from mix.exs, and the busy chat participants (of my test code) couldn’t let me use the IEx prompt.

I even tried to redirect all outputs to a dedicated process linked to the application start instead of a Supervisor, thinking that the output problem could be caused maybe by the processes hierarchy, but I had no success.

My conclusion is that should exist some kind of execution order which makes the prompt work or not.

Does anyone know if there is a reason for the IEx prompt be mixed with processes output when the Application starts automatically, but not when manually started from IEx? Is it by design? Is it Linux specific?

2 Likes