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

Acquire the GIL within createPythonPluginSystemManagerImplementationFactory #797

Closed
feltech opened this issue Jan 9, 2023 · 1 comment · Fixed by #803
Closed

Acquire the GIL within createPythonPluginSystemManagerImplementationFactory #797

feltech opened this issue Jan 9, 2023 · 1 comment · Fixed by #803
Assignees
Labels
bug Something isn't working

Comments

@feltech
Copy link
Member

feltech commented Jan 9, 2023

What

Ensure the Python GIL is acquired for the duration of createPythonPluginSystemManagerImplementationFactory, and restored to it's previous state when that function exits.

Update OpenAssetIO-Test-CMake to release the GIL before calling this function.

Why

We don't acquire the GIL within createPythonPluginSystemManagerImplementationFactory, so currently the host must acquire it before calling this.

The symptom in a Release build is an unhelpful segfault. In a Debug build you get a failed assertion telling you that the GIL must be acquired before importing modules.

Originally posted by @feltech in #554 (comment)

Notes

We should remove the warning added by #799 once this is done.

@foundrytom foundrytom added the bug Something isn't working label Jan 9, 2023
feltech added a commit to feltech/OpenAssetIO that referenced this issue Jan 9, 2023
Until OpenAssetIO#797 is properly addressed, add a warning to the Doxygen docs for
`createPythonPluginSystemManagerImplementationFactory` that the Python
GIL must be acquired before using it.

Signed-off-by: David Feltell <david.feltell@foundry.com>
@feltech
Copy link
Member Author

feltech commented Jan 9, 2023

Added #799 to add a warning to the docs until we fix this. So should be removed once the fix is in (updated issue description).

feltech added a commit to feltech/OpenAssetIO that referenced this issue Jan 26, 2023
Fixes OpenAssetIO#797. If the host thread does not hold the GIL when
`createPythonPluginSystemManagerImplementationFactory` is called, then
segfaults abound when trying to `import` the Python plugin system via
pybind11.

So ensure the GIL is acquired first. pybind11's `gil_scoped_acquire`
is clever enough to restore the state to whatever it was before, upon
function exit.

Signed-off-by: David Feltell <david.feltell@foundry.com>
feltech added a commit to feltech/OpenAssetIO that referenced this issue Jan 26, 2023
Fixes OpenAssetIO#797. If the host thread does not hold the GIL when
`createPythonPluginSystemManagerImplementationFactory` is called, then
segfaults abound when trying to `import` the Python plugin system via
pybind11.

So ensure the GIL is acquired first. pybind11's `gil_scoped_acquire`
is clever enough to restore the state to whatever it was before, upon
function exit.

Signed-off-by: David Feltell <david.feltell@foundry.com>
feltech added a commit to feltech/OpenAssetIO that referenced this issue Jan 26, 2023
Fixes OpenAssetIO#797. If the host thread does not hold the GIL when
`createPythonPluginSystemManagerImplementationFactory` is called, then
segfaults abound when trying to `import` the Python plugin system via
pybind11.

So ensure the GIL is acquired first. pybind11's `gil_scoped_acquire`
is clever enough to restore the state to whatever it was before, upon
function exit.

Signed-off-by: David Feltell <david.feltell@foundry.com>
@feltech feltech self-assigned this Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants