Skip to content

Commit

Permalink
Release the GIL while creating a Session (which accesses the Graph).
Browse files Browse the repository at this point in the history
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
stuhood committed Oct 5, 2021
1 parent a744978 commit ca44195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,17 @@ py_class!(class PySession |py| {
session_values: PyObject,
cancellation_latch: PySessionCancellationLatch,
) -> CPyResult<Self> {
let session = Session::new(
scheduler.scheduler(py),
// NB: Session creation interacts with the Graph, which must not be accessed while the GIL is
// held.
let scheduler = scheduler.scheduler(py).clone();
let cancellation_latch = cancellation_latch.cancelled(py).clone();
let session = py.allow_threads(|| Session::new(
&scheduler,
should_render_ui,
build_id,
session_values.into(),
cancellation_latch.cancelled(py).clone(),
).map_err(|err_str| PyErr::new::<exc::Exception, _>(py, (err_str,)))?;
cancellation_latch,
)).map_err(|err_str| PyErr::new::<exc::Exception, _>(py, (err_str,)))?;
Self::create_instance(py, session)
}

Expand Down
1 change: 1 addition & 0 deletions src/rust/engine/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct ExecutionRequest {
///
/// Represents the state of an execution of a Graph.
///
#[derive(Clone)]
pub struct Scheduler {
pub core: Arc<Core>,
}
Expand Down

0 comments on commit ca44195

Please sign in to comment.