Skip to content

Commit

Permalink
Fix waiting on child processes blocking indefinitely (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Mar 3, 2025
1 parent 52a9a85 commit ea29718
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/pythonx/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Pythonx.Application do

@impl true
def start(_type, _args) do
enable_sigchld()

children = [
Pythonx.Janitor
]
Expand All @@ -26,4 +28,16 @@ defmodule Pythonx.Application do
else
defp maybe_uv_init(), do: :noop
end

defp enable_sigchld() do
# Some APIs in Python, such as subprocess.run, wait for a child
# OS process to finish. On Unix, this relies on `waitpid` C API,
# which does not work properly if SIGCHLD is ignored, resulting
# in infinite waiting. ERTS ignores the signal by default, so we
# explicitly restore the default handler.
case :os.type() do
{:win32, _osname} -> :ok
{:unix, _osname} -> :os.set_signal(:sigchld, :default)
end
end
end

0 comments on commit ea29718

Please sign in to comment.