generated from kyegomez/Python-Package-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kye
committed
Mar 6, 2024
1 parent
ff947ae
commit 13362c8
Showing
5 changed files
with
72 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import sys | ||
import pyrust_parallel | ||
|
||
def my_python_function(): | ||
print("Executing Python function") | ||
|
||
g | ||
pyrust_parallel.execute_in_parallel(my_python_function, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use pyo3::types::IntoPyDict; | ||
|
||
#[test] | ||
fn test_execute_in_parallel() { | ||
let gil = Python::acquire_gil(); | ||
let py = gil.python(); | ||
let py_func = py | ||
.run( | ||
"def test_func(): return 42", | ||
None, | ||
Some(py.import("builtins").unwrap().into_py_dict(py)), | ||
) | ||
.unwrap() | ||
.extract::<PyObject>(py) | ||
.unwrap(); | ||
|
||
let result = execute_in_parallel(py, py_func, 10).unwrap(); | ||
assert_eq!(result.len(), 10); | ||
for res in result { | ||
let res: i32 = res.extract(py).unwrap(); | ||
assert_eq!(res, 42); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_execute_in_parallel_with_error() { | ||
let gil = Python::acquire_gil(); | ||
let py = gil.python(); | ||
let py_func = py | ||
.run( | ||
"def test_func(): raise ValueError('test error')", | ||
None, | ||
Some(py.import("builtins").unwrap().into_py_dict(py)), | ||
) | ||
.unwrap() | ||
.extract::<PyObject>(py) | ||
.unwrap(); | ||
|
||
let result = execute_in_parallel(py, py_func, 10); | ||
assert!(result.is_err()); | ||
} | ||
} |