Current section
Files
Jump to
Current section
Files
lib/snake_oil.ex
defmodule SnakeOil do
@moduledoc """
Documentation for `SnakeOil`.
"""
alias SnakeOil.PythonInterface
@doc """
Starts the application.
returns: {:ok, pid} | {:error, reason}
"""
def start_python_instance(working_dir, python_version \\ 'python3') do
PythonInterface.start_link([working_dir, python_version])
end
@doc """
Calls a Python function.
"""
def call_python_function(module, function, args \\ []) do
PythonInterface.call_function(module, function, args)
end
@doc """
Calls a Python function with a timeout.
"""
def call_python_function_with_timeout(module, function, timeout, args \\ []) do
PythonInterface.call_with_timeout(module, function, timeout, args)
end
@doc """
Stops the Python instance.
"""
def stop_python_instance(pid) do
PythonInterface.terminate(pid)
end
@doc """
Call a python function without a genserver.
"""
def call_python_transient(working_dir, module, function, args \\ [], python_version \\ 'python3') do
python_directory = working_dir |> to_charlist()
python_executable = python_version
{:ok, pid} = :python.start([{:python_path, python_directory}, {:python, python_executable}])
result = :python.call(pid, module, function, args)
:python.stop(pid)
result
end
end