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

add timeout conex #48

Closed njavilas2015 closed 3 years ago

njavilas2015 commented 3 years ago

hello I wanted to know how to implement a timeout for the connection My application is simple but I need to know quickly if it is possible to connect with the remote pulse pulse = pulsectl.Pulse(server = 'ip_remote')

mk-fg commented 3 years ago

Hi,

There indeed wasn't such option, but simple enough to add, so added in 96cfaec along with a couple tests for it.

With 21.3.4, something like this should work:

with pulsectl.Pulse('myclient', server='tcp4:my-remote-ip:my-port', connect=False) as pulse:
  pulse.connect(timeout=20) # will raise pulsectl.PulseError on timeout
  ...

(note that if attempt fails with timeout, you can retry pulse.connect() call there, if necessary)

Thanks for reporting.

mk-fg commented 3 years ago

connect() got an unexpected keyword argument 'timeout'

You seem to have removed the msg, so guess probably just forgot to update the module there.

with pulsectl.Pulse('myclient', server='tcp4:192.168.88.254:4713', connect=False) as pulse:

Btw, don't think you have to spell it out as tcp4:<host>:<port> - "man pulseaudio" says that prefix and port are optional, just used that notation in tests to make ipv4/ipv6 distinction clear.