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

Pedalboard v0.9.7+ with PyQt6 crashing on Windows 10, 11 (minimal reproducible example included) #372

Open
Gdalik opened this issue Sep 1, 2024 · 2 comments

Comments

@Gdalik
Copy link

Gdalik commented Sep 1, 2024

Hi, @psobot!

I have finally managed to make the minimal reproducible example, which causes the crashing with error code -1073741819 (0xC0000005)

The script works with pedalboard v0.9.6 or lower.

@Gdalik
Copy link
Author

Gdalik commented Sep 1, 2024

UPD:

It's not about PyQt6, unfortunately.

The same result with just this:

from pedalboard.io import AudioFile

with AudioFile('PN.flac', 'r') as f:
    f.read(44100)

So, it seems to be the same issue as this

@Gdalik
Copy link
Author

Gdalik commented Feb 6, 2025

Hi, @psobot!
Haven't heard from you for quite a long time. And I hope you are doing well.
I have been testing this segfault bug for several days on different machines with Windows 10 and Windows 11, with and without different imports in the same Python project/app/script, in different environments, trying both installations from PyPi, and building PedalBoard from the source on Windows (with tools packaged with MS Visual Studio 2022) as it is or modifying the version conditions of numpy, etc. before the build.

Though I haven't found the reason why it occurs, I want to share with you some cases that may help to reproduce it, and some thoughts, impressions and insights if you don't mind.
As pointed out by @anvuew in the issue #365 and from what I experienced as well, it is more likely to occur in separate Python environments (conda environments, virtual environments and 'frozen applications' built with PyInstaller) rather than in the basic one. I do not use Anaconda, but I use Virtual Environments and PyInstaller for distributable desktop apps extensively.

On my computer with Windows 10, the basic script, opening and reading an audio file, works. On the Windows 11 machine, it didn't work initially, but it seems to have been resolved for all Python environments (virtual and basic) after installing Visual Studio tools and building Pedalboard from source. Not sure if that was the real reason, just a kind of observation.

But what remains constantly reproducible on all the Windows machines (including virtual ones like Parallels Desktop on macOS) is the failing to work properly with PyQt6. The most weird thing that I found out is that the absence or presence of the segfault depends on the order of imports. If I initialize Pedalboard importing any of its modules before PyQt6 modules, it works. If, otherwise, PyQt6 imports go first, it crashes every single time when it reaches the first point where Pedalboard tries to open any audio file or file-like object in any mode. I guess, this may be the case not only with PyQt6, but also with some other libraries as well.

Now, my 5 cents about the 0.9.6 -> 0.9.7+ transition. This bug always disappears with 0.9.6, and returns back with 0.9.7+, no matter if it uses numpy 1 or 2. I have looked attentively at your commits, and indeed, this doesn't seem to come from your codebase itself. I also tried to build the latest version (0.9.16) from the source, changing the numpy conditions in pyproject.toml file and in requirements.txt, test-requirements.txt and setup.py as well. But building with numpy v1.26.4 didn't help. Setting the pybind11 requirement to v2.12.0 had no positive result, either. Downloading 0.9.7, then reverting the version conditions (as in 0.9.6) and rebuilding didn't help either. Only installing the pre-built 0.9.6 wheels from PyPi works. My humble assumption is that there should be some other conditions, like different versions of dependencies or build tools used... But I'm sure something "unholy" happened during this transition :-)

The good news is that to workaround this and keep updating the Pedalboard versions, one can just switch the imports' order or simply write something like:

import pedalboard

at the very beginning of a script or main module of an app.
And to make it work in frozen applications built with PyInstaller, one should also add this to runtime hooks.

I'm not a technical guy and not very familiar with C++, but it looks like two Python libraries, wrapping C++ ones, are fighting for the same part of memory, which leads to segfault and crash...

Another weird thing is that I could not reproduce this bug with PySide6, which is built upon the same Qt6 framework and uses very similar codebase, but there may be differences in some parts, that are connected with Python/C++ interactions, working with GIL, etc.

Sorry for being verbose. But I felt I should share this in a hope this might be helpful.
Though I seem to have found the workaround, If this can be fixed in PedalBoard, I think it would be great and may prevent some other issues.

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

No branches or pull requests

1 participant