Skip to content

Commit

Permalink
Transmit count with delete request
Browse files Browse the repository at this point in the history
Cleaner and faster than sending multiple requests.
  • Loading branch information
coldfix committed Jul 28, 2017
1 parent f7c2c68 commit d9449fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions rpyc/core/netref.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@ def __init__(self, conn, oid):
self.____refcount__ = 1

def __del__(self):
for _ in xrange(self.____refcount__):
try:
asyncreq(self, consts.HANDLE_DEL)
except Exception:
# raised in a destructor, most likely on program termination,
# when the connection might have already been closed.
# it's safe to ignore all exceptions here
pass
try:
asyncreq(self, consts.HANDLE_DEL, self.____refcount__)
except Exception:
# raised in a destructor, most likely on program termination,
# when the connection might have already been closed.
# it's safe to ignore all exceptions here
pass

def __getattribute__(self, name):
if name in _local_netref_attrs:
Expand Down
2 changes: 1 addition & 1 deletion rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def _handle_close(self):
self._cleanup()
def _handle_getroot(self):
return self._local_root
def _handle_del(self, oid):
def _handle_del(self, oid, count=1):
self._local_objects.decref(oid)
def _handle_repr(self, oid):
return repr(self._local_objects[oid])
Expand Down
6 changes: 3 additions & 3 deletions rpyc/lib/colls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def add(self, obj):
def clear(self):
with self._lock:
self._dict.clear()
def decref(self, key):
def decref(self, key, count=1):
with self._lock:
slot = self._dict[key]
if slot[1] < 1:
if slot[1] < count:
del self._dict[key]
else:
slot[1] -= 1
slot[1] -= count
self._dict[key] = slot
def __getitem__(self, key):
with self._lock:
Expand Down

0 comments on commit d9449fc

Please sign in to comment.