The error you are receiving means that Libaudioverse is out of memory.
The decoding process takes a great deal of ram, so this is not
surprising to see in multithreaded configurations.
Leave the server's threads alone. This already does what you want.
Turning it up and down is just causing added inefficiency. All the
server's thread limit determines is how many threads will be used for
rendering audio, it doesn't affect your calls.
before we go on, I am having trouble following the logic of this
script. If I get anything wrong, this is the reason.
You appear to spawn a thread for each sound, and never wait for any of
them to finish before spawning the next one. Since Libaudioverse needs
2x the size of the sound file as a lower bound, this means Libaudioverse
is using a ton of memory. In addition, you are reading the entire file
into Python; this takes yet more memory. I suggest writing a function
to decode a single sound, finding a thread pool library, then using the
thread pool library to efficiently call your sound extracting function
on each item in the list.
Keep in mind that you are loading the file into Python strings. These
strings will stay around for an indefinite period of time and will be
quite, quite large.
The quickest fix to this script is probably to split the list of files
into a number of equally sized chunks depending on the number of cores
in the system; the multiprocessing module provides a function
multiprocessing.cpu_count() that will tell you how many there are.
Your logic with the locks appears to be holding it for the duration of
the decoding. This means that you are not actually getting much benefit
from using threads. I suspect this script isn't much faster with them
than without.
Your waiting logic is also going to completely eat a core: if you insist
on trying to do this without using a thread pool library, I suggest
looking at threading.Semaphore.
Once you do get this not eating all the ram and fix the lock so it
actually provides a benefit, I suspect you are going to also find a
bunch of thread safety bugs. Please, please find and use a library, or
at least the Queue module.
You don't want to start and abandon threads after each file: this has a
huge amount of overhead. As an idea of how much, multithreaded
Libaudioverse runs orders of magnitude faster, but multithreaded
Libaudioverse with an internal bug that accidentally stops them after
every block of audio was worse than just not bothering.
Even if you do get all this working, keep in mind that the bottleneck
here is likely to be the hard drive. What I mean is that threads will
only really benefit you on a system with an SSD. Zip files do not
compress audio by very much. Count on needing at least 20mb/s hard disk
I/O bandwidth per thread for decoding wave files. Given that the OS and
other parts of your game are also probably taking some, this will
probably not be available on all systems anyway. Libaudioverse decodes
even large wave files practically instantly as-is. The decoding
overhead comes in for other formats such as ogg; these formats are much,
much smaller, so the CPU has a chance to be a bottleneck.
Code like this script is why I encourage people to not use threads until
they have absolutely no other choice. If you learn nothing else from
this, please walk away with the understanding that threads are one of
the hardest things to get right as a programmer, not one of the
easiest. Your script is going to load sounds exactly once. Going
through the trouble to have threads so that this can take maybe a few
seconds less is not worth it.
In so far as I can tell and pending further information, this doesn't
look like a Libaudioverse bug. If you still think it is, I'm going to
need your test sounds and information on the computer you're testing
this on. There is a slight possibility that something is wrong, but I
really think it's the script.