forked from platypush/platypush
As python-mpd2 doesn't seem to be quite thread-safe, the mpd plugin entry-point has now got a reentrant lock
This commit is contained in:
parent
d9e21d22d3
commit
ca24243449
1 changed files with 10 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
import mpd
|
import mpd
|
||||||
import re
|
import re
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from platypush.plugins import action
|
from platypush.plugins import action
|
||||||
|
@ -20,6 +21,8 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
* **python-mpd2** (``pip install python-mpd2``)
|
* **python-mpd2** (``pip install python-mpd2``)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_client_lock = RLock()
|
||||||
|
|
||||||
def __init__(self, host, port=6600):
|
def __init__(self, host, port=6600):
|
||||||
"""
|
"""
|
||||||
:param host: MPD IP/hostname
|
:param host: MPD IP/hostname
|
||||||
|
@ -46,7 +49,10 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._connect()
|
self._connect()
|
||||||
|
response = None
|
||||||
|
with self._client_lock:
|
||||||
response = getattr(self.client, method)(*args, **kwargs)
|
response = getattr(self.client, method)(*args, **kwargs)
|
||||||
|
|
||||||
if return_status:
|
if return_status:
|
||||||
return self.status().output
|
return self.status().output
|
||||||
return response
|
return response
|
||||||
|
@ -170,8 +176,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
volume = int(self.status().output['volume'])
|
volume = int(self.status().output['volume'])
|
||||||
new_volume = min(volume+delta, 100)
|
new_volume = min(volume+delta, 100)
|
||||||
self.setvol(str(new_volume))
|
return self.setvol(str(new_volume))
|
||||||
return self.status()
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def voldown(self, delta=10):
|
def voldown(self, delta=10):
|
||||||
|
@ -184,8 +189,7 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
|
|
||||||
volume = int(self.status().output['volume'])
|
volume = int(self.status().output['volume'])
|
||||||
new_volume = max(volume-delta, 0)
|
new_volume = max(volume-delta, 0)
|
||||||
self.setvol(str(new_volume))
|
return self.setvol(str(new_volume))
|
||||||
return self.status()
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def random(self, value=None):
|
def random(self, value=None):
|
||||||
|
@ -439,9 +443,8 @@ class MusicMpdPlugin(MusicPlugin):
|
||||||
Returns the list of playlists and directories on the server
|
Returns the list of playlists and directories on the server
|
||||||
"""
|
"""
|
||||||
|
|
||||||
output = self._exec('lsinfo', uri, return_status=False) \
|
return self._exec('lsinfo', uri, return_status=False) \
|
||||||
if uri else self._exec('lsinfo', return_status=False)
|
if uri else self._exec('lsinfo', return_status=False)
|
||||||
return output
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def plchanges(self, version):
|
def plchanges(self, version):
|
||||||
|
|
Loading…
Reference in a new issue