From 94dbe362d1e12fb0c48bb795aecc1180d6a1a690 Mon Sep 17 00:00:00 2001 From: comrumino Date: Sat, 2 Jul 2022 13:41:07 -0500 Subject: [PATCH] Replaced finally block with else and generalized the except block for non-EOFError to release lock --- rpyc/core/protocol.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/rpyc/core/protocol.py b/rpyc/core/protocol.py index a205ac1e..c30bb1f6 100644 --- a/rpyc/core/protocol.py +++ b/rpyc/core/protocol.py @@ -389,18 +389,24 @@ def serve(self, timeout=1, wait_for_lock=True): # serving return False # Assume the receive rlock is acquired and incremented try: + data = None # Ensure data is initialized data = self._channel.poll(timeout) and self._channel.recv() - if not data: - return False - except EOFError: - self.close() # sends close async request + except Exception as exc: + if isinstance(exc, EOFError): + self.close() # sends close async request + self._recvlock.release() + with self._recv_event: + self._recv_event.notify_all() raise - finally: + else: self._recvlock.release() with self._recv_event: self._recv_event.notify_all() - self._dispatch(data) - return True + if not data: + return False + else: + self._dispatch(data) + return True def poll(self, timeout=0): # serving """Serves a single transaction, should one arrives in the given