[CentralOH] Async buffer generation update

Brian Costlow 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,
https://docs.python.org/3/library/asyncio-eventloop.html?highlight=asyncio%20executor#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,
like:

https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor

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>
wrote:

> 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)
>     sound_process.start()
>
>
> 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?).
>
> -Eric
>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20160622/82e824e8/attachment.html>


More information about the CentralOH mailing list