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

Add explicit Numpy import to workaround GIL deadlock with asyncio. #155

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

psobot
Copy link
Member

@psobot psobot commented Oct 24, 2022

See #154.

In certain situations (including when using asyncio), Pedalboard's C++ code will implicitly and lazily import NumPy via its Pybind11 bindings. This lazy import can sometimes (!) cause a deadlock on the GIL if multiple threads are attempting it simultaneously. To work around this, we preload Numpy into the current Python process so that Pybind11's lazy import is effectively a no-op.

No tests included here: the buggy behaviour occurs when numpy isn't loaded into the running Python process, which is very hard to simulate in test without running a subprocess and writing a very elaborate (and likely brittle) test.

@psobot
Copy link
Member Author

psobot commented Oct 24, 2022

Merging despite failing tests (which are failing due to documentation not passing; need to clean up that flakey CI setup).

@psobot psobot merged commit 40275fa into master Oct 24, 2022
@psobot psobot deleted the psobot/fix-deadlock branch October 24, 2022 19:55
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
None yet
Development

Successfully merging this pull request may close these issues.

1 participant