File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,20 @@ Pythonx runs a Python interpreter in the same OS process as your Elixir
1111application, allowing you to evaluate Python code and conveniently
1212convert 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
1630Add Pythonx to your dependencies:
Original file line number Diff line number Diff 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
2832end
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
You can’t perform that action at this time.
0 commit comments