Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 163 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ tokio = { version = "1.47.0", features = ["sync", "macros", "rt", "rt-multi-thre
default = ["pyo3"]
# default = ["rustpython"]
pyo3 = ["dep:pyo3"]
rustpython = ["dep:rustpython-vm", "dep:rustpython-stdlib"]
rustpython = ["dep:rustpython-vm", "dep:rustpython", "dep:rustpython-stdlib"]

[dependencies.pyo3]
version = "0.26.0"
version = "0.26"
features = ["auto-initialize"]
optional = true

Expand All @@ -33,6 +33,10 @@ version = "0.4.0"
optional = true
features = ["threading", "serde", "importlib"]

[dependencies.rustpython]
version = "0.4.0"
optional = true

[dependencies.rustpython-stdlib]
version = "0.4.0"
optional = true
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Each call will use its own event loop. This may not be very efficient and change

Make sure to use `call_async_function` for async python functions. Using `call_function` will
probably raise an error.
`call_async_function` is not available for RustPython.

### Using a venv
It is generally recommended to use a venv to install pip packages.
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ pub struct PyRunner {
sender: mpsc::Sender<PyCommand>,
}


impl Default for PyRunner {
fn default() -> Self {
PyRunner::new()
Expand Down Expand Up @@ -124,7 +123,9 @@ impl PyRunner {

#[cfg(feature = "rustpython")]
{
rustpython_runner::python_thread_main(receiver);
use tokio::runtime::Builder;
let rt = Builder::new_current_thread().enable_all().build().unwrap();
rt.block_on(rustpython_runner::python_thread_main(receiver));
}
});

Expand Down Expand Up @@ -347,7 +348,6 @@ impl PyRunner {
/// * `args`: A vector of `serde_json::Value` to pass as arguments to the function.
///
/// **Note:** This function is safe to call from any context (sync or async).
#[cfg(feature = "pyo3")]
pub fn call_async_function_sync(
&self,
name: &str,
Expand Down Expand Up @@ -548,7 +548,6 @@ def add(a, b):
);
}

#[cfg(feature = "pyo3")]
#[tokio::test]
async fn test_run_with_async_function() {
let executor = PyRunner::new();
Expand All @@ -569,11 +568,11 @@ async def add_and_sleep(a, b, sleep_time):
let result2 =
executor.call_async_function("add_and_sleep", vec![5.into(), 10.into(), 0.1.into()]);
let (result1, result2) = tokio::join!(result1, result2);
// The order of execution is guaranteed by the last timing parameters
assert_eq!(result1.unwrap(), Value::Number(17.into()));
assert_eq!(result2.unwrap(), Value::Number(16.into()));
}

#[cfg(feature = "pyo3")]
#[test]
fn test_run_with_async_function_sync() {
let executor = PyRunner::new();
Expand Down
Loading
Loading