Support free-threaded Python #469
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Closes #467
This adds support for Python 3.14 and 3.14t as well as supporting free-threaded Python.
I've opted to add a
threading.RLock
member to theSoundFile
object. I also made it so all the public methods ofSoundFile
that access the_file
handle need to acquire the lock via a newwith_lock
decorator.I'm using an
RLock
to avoid the need to refactor to avoid possibly reentrancy. I can probably use athreading.Lock
instead but it will be trickier to get right.Also adds tests for supported workflows (each thread has its own
SoundFile
) as well as unsupported workflows.You could also support the free-threaded build without adding the locking. IMO the locking is a nicer user experience. With this approach if you try to use a
SoundFile
object in more than one thread simultaneously, you will see a RuntimeError if there is any concurrent use. Since I'm using the non-blocking variant ofRLock.acquire()
, it's impossible for this to introduce new scaling issues. Acquiring an uncontended lock is very low-overhead so I don't expect this to add much overhead.I ran the tests under TSan and didn't see any issues besides a known race in
BytesIO
in 3.14 that should be fixed in 3.14.1. I can add TSan CI as a followup if you'd like.