Skip to content

Commit 83dfb5d

Browse files
committed
Feedback
1 parent 838936b commit 83dfb5d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ Pythonx runs a Python interpreter in the same OS process as your Elixir
1111
application, allowing you to evaluate Python code and conveniently
1212
convert between Python and Elixir data structures.
1313

14+
The goal of this project is to better integrate Python workflows within
15+
Livebook and its usage in actual projects must be done with care due to
16+
Python's global interpreter lock (GIL), which prevents from multiple threads
17+
executing Python code at the same time. Consequently, calling `Pythonx`
18+
from multiple Elixir processes does not provide the concurrency you might
19+
expect and thus it can be a source of bottlenecks. However, this concerns
20+
regular Python code. Packages with CPU-intense functionality, such as `numpy`,
21+
have native implementation of many functions and invoking those releases the
22+
GIL. GIL is also released when waiting on I/O operations. In other words,
23+
if you are using this library to integrate with Python, make sure it happens
24+
in a single Elixir process or that its underlying libraries can deal with
25+
concurrent invocation. Otherwqise, prefer to use Elixir's `System.cmd/3` or
26+
`Port`s to manage multiple Python programs via I/O.
27+
1428
## Usage (script)
1529

1630
Add Pythonx to your dependencies:

lib/pythonx/application.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ defmodule Pythonx.Application do
2020

2121
# If configured, Python and dependencies are fetched at compile time,
2222
# so we automatically initialize the interpreter on boot.
23+
#
24+
# TODO: My suggestion would be to call ut :pythonx, :uv_init, to make
25+
# it clear it will start the runtime.
2326
if pyproject_toml = Application.compile_env(:pythonx, :uv)[:pyproject_toml] do
27+
Pythonx.Uv.fetch(pyproject_toml, true)
2428
defp maybe_uv_init(), do: Pythonx.Uv.init(unquote(pyproject_toml), true)
2529
else
2630
defp maybe_uv_init(), do: :noop
2731
end
2832
end
29-
30-
# If configured, fetch Python and dependencies when compiling.
31-
if pyproject_toml = Application.compile_env(:pythonx, :uv)[:pyproject_toml] do
32-
Pythonx.Uv.fetch(pyproject_toml, true)
33-
end

0 commit comments

Comments
 (0)