Skip to content

Commit

Permalink
Added comments to explain why _recvlock is an RLock
Browse files Browse the repository at this point in the history
  • Loading branch information
comrumino committed Jul 2, 2022
1 parent 299ca14 commit 9903738
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def __init__(self, root, channel, config={}):
self._HANDLERS = self._request_handlers()
self._channel = channel
self._seqcounter = itertools.count()
self._recvlock = RLock()
self._recvlock = RLock() # AsyncResult implementation means that synchronous requests have multiple acquires
self._sendlock = Lock()
self._recv_event = Condition() # TODO: current use may suggest we could simply timeout and catch an acquire
self._recv_event = Condition() # TODO: why not simply timeout? why not associate w/ recvlock? explain/redesign
self._request_callbacks = {}
self._local_objects = RefCountingColl()
self._last_traceback = None
Expand Down Expand Up @@ -477,17 +477,17 @@ def poll_all(self, timeout=0): # serving
pass
return at_least_once

def sync_request(self, handler, *args): # serving
def sync_request(self, handler, *args):
"""requests, sends a synchronous request (waits for the reply to arrive)
:raises: any exception that the requets may be generated
:returns: the result of the request
"""
timeout = self._config["sync_request_timeout"]
# AsyncResult will be constructed and it is possible GIL switches
# threads before AsyncResult.wait is invoked.
value = self.async_request(handler, *args, timeout=timeout).value
return value
_async_res = self.async_request(handler, *args, timeout=timeout)
# _async_res is an instance of AsyncResult, the value property invokes Connection.serve via AsyncResult.wait
# So, the _recvlock can be acquired multiple times by the owning thread and warrants the use of RLock
return _async_res.value

def _async_request(self, handler, args=(), callback=(lambda a, b: None)): # serving
seq = self._get_seq_id()
Expand Down

0 comments on commit 9903738

Please sign in to comment.