Skip to content

What is the proper way to link a process in Livebook? (e.g. when running Flows/GenStage in separate processes) #1614

Answered by jonatanklosko
linusdm asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @linusdm!

Whenever we do start_link explicitly, it ties the given process to Livebook evaluation process, so if the linked process crashes, so does the evaluation process, and consequently all the state/variables is gone. Usually we would put such process in our app suprevision tree and in Livebook the counterpart is to use Kino.start_child/1, which makes sure the process is terminated when you reevaluate the cell.

When you do define your own module like MyFlow and do use Flow, it defines child_spec for you, so you can do this:

defmodule MyFlow do
  use Flow

  def start_link(_) do
    # ...
    |> Flow.start_link()
  end
end

Kino.start_child(MyFlow)

If you don't want to define a mod…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@josevalim
Comment options

@josevalim
Comment options

@linusdm
Comment options

Answer selected by linusdm
Comment options

You must be logged in to vote
1 reply
@josevalim
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants