[Pkg-mpd-commits] [python-mpd] 43/91: Synchronize ``lineReceived`` and ``_execute`` methods on twisted protocol

Simon McVittie smcv at debian.org
Sat Feb 24 14:55:33 UTC 2018


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository python-mpd.

commit d84c925cee789add327b1c5701ba75656532a93b
Author: Robert Niederreiter <office at squarewave.at>
Date:   Sun Jan 29 13:48:52 2017 +0100

    Synchronize ``lineReceived`` and ``_execute`` methods on twisted protocol
---
 mpd/twisted.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mpd/twisted.py b/mpd/twisted.py
index d414ac2..d8699ea 100644
--- a/mpd/twisted.py
+++ b/mpd/twisted.py
@@ -37,9 +37,17 @@ from mpd.base import mpd_command_provider
 from mpd.base import mpd_commands
 from twisted.internet import defer
 from twisted.protocols import basic
+import threading
 import types
 
 
+def lock(func):
+    def wrapped(self, *args, **kwargs):
+        with self._lock:
+            return func(self, *args, **kwargs)
+    return wrapped
+
+
 def _create_command(wrapper, name, callback):
     def mpd_command(self, *args):
         def bound_callback(lines):
@@ -59,6 +67,7 @@ class MPDProtocol(basic.LineReceiver, MPDClientBase):
         self._default_idle = default_idle
         self.idle_result = idle_result
         self._reset()
+        self._lock = threading.RLock()
 
     def _reset(self):
         super(MPDProtocol, self)._reset()
@@ -79,6 +88,7 @@ class MPDProtocol(basic.LineReceiver, MPDClientBase):
         escaped_name = name.replace(' ', '_')
         setattr(cls, escaped_name, func)
 
+    @lock
     def lineReceived(self, line):
         line = line.decode('utf-8')
         command_list = self._state and isinstance(self._state[0], list)
@@ -115,6 +125,7 @@ class MPDProtocol(basic.LineReceiver, MPDClientBase):
             return parser.callback
         return parser
 
+    @lock
     def _execute(self, command, args, parser):
         # close or kill command in command list not allowed
         if self._command_list and self._lookup_callback(parser) is self.NOOP:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mpd/python-mpd.git



More information about the Pkg-mpd-commits mailing list