From cc559a7e50d7010417214772b58803f9b2aba7bf Mon Sep 17 00:00:00 2001 From: Damien Stuart Date: Sun, 31 Dec 2017 16:00:57 -0500 Subject: [PATCH] Ensure the lock is released if there is an exception on socket I/O. --- pigpio.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pigpio.py b/pigpio.py index df01c0d..5d22c55 100644 --- a/pigpio.py +++ b/pigpio.py @@ -980,8 +980,12 @@ def _pigpio_command(sl, cmd, p1, p2, rl=True): p2:= command parameter 2 (if applicable). """ sl.l.acquire() - sl.s.send(struct.pack('IIII', cmd, p1, p2, 0)) - dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN)) + try: + sl.s.send(struct.pack('IIII', cmd, p1, p2, 0)) + dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN)) + except Exception, e: + sl.l.release() + raise(e) if rl: sl.l.release() return res @@ -1003,8 +1007,12 @@ def _pigpio_command_ext(sl, cmd, p1, p2, p3, extents, rl=True): else: ext.extend(x) sl.l.acquire() - sl.s.sendall(ext) - dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN)) + try: + sl.s.sendall(ext) + dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN)) + except Exception, e: + sl.l.release() + raise(e) if rl: sl.l.release() return res