Skip to content

Commit

Permalink
Release the GIL while creating a Session. (pantsbuild#13127)
Browse files Browse the repository at this point in the history
Creating a `Session` accesses the `Graph` to get the number of valid nodes, but when created under the `PySession` wrapper, does so while holding the GIL.

Release the GIL in `PySession`.

[ci skip-build-wheels]
 Conflicts:

[ci skip-jvm-tests]
  • Loading branch information
stuhood committed Oct 6, 2021
1 parent e598706 commit 4f5b7a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/rust/engine/src/externs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,17 @@ py_class!(class PySession |py| {
build_id: String,
should_report_workunits: bool
) -> CPyResult<Self> {
Self::create_instance(py, Session::new(
scheduler_ptr.scheduler(py),
// NB: Session creation interacts with the Graph, which must not be accessed while the GIL is
// held.
let core = scheduler_ptr.scheduler(py).core.clone();
let session = py.allow_threads(|| Session::new(
core,
should_record_zipkin_spans,
should_render_ui,
build_id,
should_report_workunits,
)
)
));
Self::create_instance(py, session)
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct Session(Arc<InnerSession>);

impl Session {
pub fn new(
scheduler: &Scheduler,
core: Arc<Core>,
should_record_zipkin_spans: bool,
should_render_ui: bool,
build_id: String,
Expand All @@ -94,7 +94,7 @@ impl Session {
};

let inner_session = InnerSession {
preceding_graph_size: scheduler.core.graph.len(),
preceding_graph_size: core.graph.len(),
roots: Mutex::new(HashMap::new()),
display,
should_record_zipkin_spans,
Expand Down

0 comments on commit 4f5b7a1

Please sign in to comment.