You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need thread safety for python-mpd2, therefore I added a method to my class and wrap all calls to mpd over the method below.
This seems to work ok (except that I have trouble to catch the Connection Error, but this is a different story)
Now I wanted to do this a little bit more pythonic.
I was thinking about inheriting the MPDClient class and overwrite either the mpd_commands(object): decorator or the mpd_command_provider(cls): decorator incorporating the mutex below.
Would one of these methods be the be the right approach?
Does one have an other proposal?
def mpd_retry_with_mutex(self, mpd_cmd, params=None):
retry = 2
with self.mpd_mutex:
while retry:
try:
if params is None:
ret = mpd_cmd()
else:
ret = mpd_cmd(params)
break
except ConnectionError:
if retry:
retry -= 1
self.connect()
else:
ret = {}
break
return ret
The text was updated successfully, but these errors were encountered:
I need thread safety for python-mpd2, therefore I added a method to my class and wrap all calls to mpd over the method below.
This seems to work ok (except that I have trouble to catch the Connection Error, but this is a different story)
Now I wanted to do this a little bit more pythonic.
I was thinking about inheriting the MPDClient class and overwrite either the mpd_commands(object): decorator or the mpd_command_provider(cls): decorator incorporating the mutex below.
Would one of these methods be the be the right approach?
Does one have an other proposal?
The text was updated successfully, but these errors were encountered: