mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

Integration with Asyncio #32

Closed thiagokokada closed 5 years ago

thiagokokada commented 5 years ago

First, thanks! This is a great library. I am writing a asyncio based library and I am integrating pulsectl on it.

For now I just started a thread and let pulsectl run on it, however it would be interesting to have proper asyncio integration with pulsectl with it. I saw the other issue with gobject (https://github.com/mk-fg/python-pulse-control/issues/11) and I am interested if you know some tips on how to integrate pulsectl with async.

mk-fg commented 5 years ago

Hi,

There's also https://github.com/mk-fg/python-pulse-control#event-handling-code-threads section in the README about such eventloop integration. Specifically, I think you'd want to use set_poll_func wrapper, which libpulse exposes for that. Don't think it should break high-level wrappers if you're willing to treat libpulse calls as instant/blocking ones, but as also mentioned there, didn't really look into such integration myself beyond what mentioned in #11 already.

Ideally for asyncio there'd have to be an entirely separate module - e.g. aiopulsectl - which would have all its calls async (which they are, especially if you're accessing pulse over crappy network), but that'd be an entirely different code with different api. It should be relatively straightforward to implement on top of same ctypes wrappers (with asyncio poller callback set), especially if you only need like 5 calls from there, so I'd probably do that instead of trying to shoehorn this module into asyncio project in a blocking fashion.

If you'll end up going the second way (a proper asyncio libpulse wrapper), I'd suggest posting it to github/pypi, even if it'll end up having just a few calls that you need wrapped - that's how this one started too, and turned out to be useful to people somehow anyway :)