Skip to content

Commit 2b7d62e

Browse files
Update docs and config (#1)
Co-authored-by: Jonatan Kłosko <[email protected]>
1 parent 838936b commit 2b7d62e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

Lines changed: 15 additions & 1 deletion
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:
@@ -104,7 +118,7 @@ Configure the desired Python version and dependencies in your
104118
```elixir
105119
import Config
106120

107-
config :pythonx, :uv,
121+
config :pythonx, :uv_init,
108122
pyproject_toml: """
109123
[project]
110124
name = "project"

lib/pythonx/application.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ defmodule Pythonx.Application do
1818
end
1919
end
2020

21-
# If configured, Python and dependencies are fetched at compile time,
22-
# so we automatically initialize the interpreter on boot.
23-
if pyproject_toml = Application.compile_env(:pythonx, :uv)[:pyproject_toml] do
21+
# If configured, we fetch Python and dependencies at compile time
22+
# and we automatically initialize the interpreter on boot.
23+
if pyproject_toml = Application.compile_env(:pythonx, :uv_init)[:pyproject_toml] do
24+
Pythonx.Uv.fetch(pyproject_toml, true)
2425
defp maybe_uv_init(), do: Pythonx.Uv.init(unquote(pyproject_toml), true)
2526
else
2627
defp maybe_uv_init(), do: :noop
2728
end
2829
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)