Skip to content

Commit ea29718

Browse files
Fix waiting on child processes blocking indefinitely (#15)
1 parent 52a9a85 commit ea29718

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/pythonx/application.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ defmodule Pythonx.Application do
55

66
@impl true
77
def start(_type, _args) do
8+
enable_sigchld()
9+
810
children = [
911
Pythonx.Janitor
1012
]
@@ -26,4 +28,16 @@ defmodule Pythonx.Application do
2628
else
2729
defp maybe_uv_init(), do: :noop
2830
end
31+
32+
defp enable_sigchld() do
33+
# Some APIs in Python, such as subprocess.run, wait for a child
34+
# OS process to finish. On Unix, this relies on `waitpid` C API,
35+
# which does not work properly if SIGCHLD is ignored, resulting
36+
# in infinite waiting. ERTS ignores the signal by default, so we
37+
# explicitly restore the default handler.
38+
case :os.type() do
39+
{:win32, _osname} -> :ok
40+
{:unix, _osname} -> :os.set_signal(:sigchld, :default)
41+
end
42+
end
2943
end

0 commit comments

Comments
 (0)