forked from livebook-dev/pythonx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.ex
More file actions
43 lines (35 loc) · 1.21 KB
/
Copy pathapplication.ex
File metadata and controls
43 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
defmodule Pythonx.Application do
@moduledoc false
use Application
@impl true
def start(_type, _args) do
enable_sigchld()
children = [
Pythonx.Janitor
]
opts = [strategy: :one_for_one, name: Pythonx.Supervisor]
with {:ok, result} <- Supervisor.start_link(children, opts) do
maybe_uv_init()
{:ok, result}
end
end
# If configured, we fetch Python and dependencies at compile time
# and we automatically initialize the interpreter on boot.
if pyproject_toml = Application.compile_env(:pythonx, :uv_init)[:pyproject_toml] do
Pythonx.Uv.fetch(pyproject_toml, true)
defp maybe_uv_init(), do: Pythonx.Uv.init(unquote(pyproject_toml), true)
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