Skip to content

Commit 729943b

Browse files
committed
chore: Clone should hold GIL
1 parent d797114 commit 729943b

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

packages/cubejs-backend-native/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ index.node
66
**/node_modules
77
**/.DS_Store
88
npm-debug.log
9+
test/__pycache__/
10+
test/subdir_for_test/__pycache__/

packages/cubejs-backend-native/src/cross/clrepr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ pub enum StringType {
9898
Safe,
9999
}
100100

101-
/// Cross language representation is abstraction to transfer values between
101+
/// Cross-language representation is an abstraction to transfer values between
102102
/// JavaScript and Python across Rust. Converting between two different languages requires
103-
/// to use Context which is available on the call (one for python and one for js), which result as
103+
/// using Context which is available on the call (one for python and one for js), which results as
104104
/// blocking.
105105
#[derive(Debug, Clone)]
106106
pub enum CLRepr {

packages/cubejs-backend-native/src/cross/clrepr_python.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use pyo3::types::{
88
};
99
use pyo3::{Bound, Py, PyAny, PyErr, PyObject, Python, ToPyObject};
1010

11-
#[derive(Debug, Clone)]
11+
#[derive(Debug)]
1212
pub enum PythonRef {
1313
PyObject(PyObject),
1414
PyFunction(Py<PyFunction>),
@@ -17,6 +17,16 @@ pub enum PythonRef {
1717
PyExternalFunction(Py<PyFunction>),
1818
}
1919

20+
impl Clone for PythonRef {
21+
fn clone(&self) -> Self {
22+
Python::with_gil(|py| match self {
23+
PythonRef::PyObject(obj) => PythonRef::PyObject(obj.clone_ref(py)),
24+
PythonRef::PyFunction(fun) => PythonRef::PyFunction(fun.clone_ref(py)),
25+
PythonRef::PyExternalFunction(fun) => PythonRef::PyExternalFunction(fun.clone_ref(py)),
26+
})
27+
}
28+
}
29+
2030
impl CLRepr {
2131
/// Convert python value to CLRepr
2232
pub fn from_python_ref(v: &Bound<'_, PyAny>) -> Result<Self, PyErr> {

packages/cubejs-backend-native/src/cross/py_in_js.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::cross::CLRepr;
22
use crate::python::runtime::py_runtime;
33
use neon::prelude::*;
44
use pyo3::types::PyFunction;
5-
use pyo3::Py;
5+
use pyo3::{Py, Python};
66
use std::cell::RefCell;
77

88
pub struct JsPyFunctionWrapper {
@@ -43,7 +43,7 @@ pub fn cl_repr_py_function_wrapper(mut cx: FunctionContext) -> JsResult<JsPromis
4343
)?);
4444
}
4545

46-
let py_method = this.borrow().fun.clone();
46+
let py_method = Python::with_gil(|py| this.borrow().fun.clone_ref(py));
4747
let py_runtime = match py_runtime() {
4848
Ok(r) => r,
4949
Err(err) => return cx.throw_error(format!("Unable to init python runtime: {:?}", err)),

0 commit comments

Comments
 (0)