[CentralOH] Async buffer generation update
brian.costlow at gmail.com
Wed Jun 22 18:09:45 EDT 2016
Yes, more or less. The event loop runs in one thread and the concurrency is
provided by coroutine based "green threads".
If you look at the link Andrew provided for Executor,
The default is to execute the coro in a separate thread in a threadpool,
but in theory if you replaced the default executor with a process executor,
That would move cpu bound coroutines to a different process and be parallel.
At that point, you are doing Celery without a broker. I'll leave it up to
you whether that would be a good thing or a bad thing for your use case ;-)
On Wed, Jun 22, 2016 at 4:53 PM, Eric Floehr <eric at intellovations.com>
> Thank you Neil and Andrew for getting me pointed in the right direction.
> Here is where I am now.
> I've taken Neil's suggestion of a Queue, and am using the multiprocessing
> module's Queue which is thread-safe, and am using that as the audio buffer.
> I then use multiprocessing's Process class to throw the generation process
> into a separate process, like so:
> import multiprocessing
> audio_bytes = multiprocessing.Queue(maxsize=int(RATE/4.0))
> def generate_samples():
> while True:
> audio_bytes.put((round(random.random() * VOLRANGE) + MINVOL))
> def get_samples(in_data, frame_count, time_info, status_flags):
> out_data = b""
> for _ in range(frame_count):
> out_data += pack('h', audio_bytes.get())
> return out_data, pyaudio.paContinue
> def main():
> sound_process = multiprocessing.Process(target=generate_samples)
> Currently, I'm using a buffer size of a quarter of a second. I'm still not
> using a generator to create the samples, but I'm working towards that. I
> wanted to get the basics down first.
> I also thought that I could use asyncio's ensure_future() to accomplish
> effectively the same thing effectively, except asyncio is just concurrent,
> whereas multiprocessing is parallel (I believe?).
> CentralOH mailing list
> CentralOH at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH