Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release the GIL while creating a Session. #13127

Merged

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Oct 5, 2021

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]

// held.
let scheduler = scheduler.scheduler(py).clone();
let cancellation_latch = cancellation_latch.cancelled(py).clone();
let session = py.allow_threads(|| Session::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to ensure the "no GIL" condition for Graph access? Should Graph methods panic if the GIL is held?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... good idea. But I don't see a way to check whether the GIL is already acquired, and it's probably not worth adding thread local state for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Yea, I think peppering a reusable debug assert around would be a great idea. I'll do that in a followup though, since it would be hard to cherry pick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@stuhood stuhood enabled auto-merge (squash) October 6, 2021 03:38
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood force-pushed the stuhood/release-gil-during-session-creation branch from ca44195 to 576dee5 Compare October 6, 2021 18:17
@stuhood stuhood merged commit 221dc1b into pantsbuild:main Oct 6, 2021
@stuhood stuhood deleted the stuhood/release-gil-during-session-creation branch October 6, 2021 19:32
stuhood added a commit to stuhood/pants that referenced this pull request Oct 6, 2021
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]
stuhood added a commit that referenced this pull request Oct 7, 2021
)

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]
[ci skip-jvm-tests]
stuhood added a commit to stuhood/pants that referenced this pull request Oct 7, 2021
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]
stuhood added a commit that referenced this pull request Oct 8, 2021
)

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants