Skip to content

Conversation

@davidhewitt
Copy link
Member

Followup to #5317

This adds Python::try_attach, an alternative to Python::attach which avoids attempting to attach to the interpreter when the interpreter is not in a suitable state for doing so.

Only last commit is new, will leave in draft until suitable for review.

@davidhewitt davidhewitt marked this pull request as ready for review August 21, 2025 18:27
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

I wonder whether try_acquire should maybe return a Result instead, such that it is possible to check the failure cause. This would allow us to reuse try_acquire in normal attach (lifting the auto-initialize into attach) and keep individual panic messages.


While we're here, we should add the GC traversal panic to the attach documentation.

@davidhewitt
Copy link
Member Author

Good idea, I pushed a commit to make that adjustment and do a bit of general tidying up at the same time.

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Great, looks good!


Just noticed that we should do a follow up to rename Python::assume_gil_acquired() into Python::assume_attached

@davidhewitt
Copy link
Member Author

Ah yes and we should include that in 0.26 too. 👍

@davidhewitt davidhewitt enabled auto-merge August 21, 2025 20:48
@davidhewitt davidhewitt mentioned this pull request Aug 21, 2025
@davidhewitt davidhewitt added this pull request to the merge queue Aug 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 22, 2025
@davidhewitt davidhewitt enabled auto-merge August 22, 2025 14:19
@davidhewitt davidhewitt added this pull request to the merge queue Aug 22, 2025
Merged via the queue into PyO3:main with commit 39bf3b8 Aug 22, 2025
43 of 44 checks passed
@davidhewitt davidhewitt deleted the add-try-attach branch August 22, 2025 16:22
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