Skip to content

Commit

Permalink
fixing the function def wait by not waiting for the completion call
Browse files Browse the repository at this point in the history
  • Loading branch information
achrafka committed Nov 6, 2021
1 parent 1238f48 commit 5feb06c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true,
"python.terminal.activateEnvironment": true,
"python.venvPath": "${workspaceFolder}\\.venv",
"python.pythonPath": "C:\\Users\\${env:USERNAME}\\AppData\\Local\\Programs\\Python\\Python37\\python.exe"
"python.venvPath": "${workspaceFolder}\\.venv"
}
21 changes: 11 additions & 10 deletions rpyc/core/async_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time # noqa: F401
from threading import Event
from rpyc.lib import Timeout
from rpyc.lib.compat import TimeoutError as AsyncResultTimeout

Expand All @@ -12,29 +13,29 @@ class AsyncResult(object):

def __init__(self, conn):
self._conn = conn
self._is_ready = False
self._is_ready = Event()
self._is_exc = None
self._obj = None
self._callbacks = []
self._ttl = Timeout(None)

def __repr__(self):
if self._is_ready:
if self._is_ready.is_set():
state = "ready"
elif self._is_exc:
state = "error"
elif self.expired:
state = "expired"
else:
state = "pending"
return "<AsyncResult object (%s) at 0x%08x>" % (state, id(self))
return f"<AsyncResult object ({state}) at 0x{id(self):08x}>"

def __call__(self, is_exc, obj):
if self.expired:
return
self._is_exc = is_exc
self._obj = obj
self._is_ready = True
self._is_ready.set()
for cb in self._callbacks:
cb(self)
del self._callbacks[:]
Expand All @@ -43,9 +44,9 @@ def wait(self):
"""Waits for the result to arrive. If the AsyncResult object has an
expiry set, and the result did not arrive within that timeout,
an :class:`AsyncResultTimeout` exception is raised"""
while not self._is_ready and not self._ttl.expired():
while not self._is_ready.is_set() and not self._ttl.expired():
self._conn.serve(self._ttl)
if not self._is_ready:
if not self._is_ready.is_set():
raise AsyncResultTimeout("result expired")

def add_callback(self, func):
Expand All @@ -56,7 +57,7 @@ def add_callback(self, func):
:param func: the callback function to add
"""
if self._is_ready:
if self._is_ready.is_set():
func(self)
else:
self._callbacks.append(func)
Expand All @@ -72,12 +73,12 @@ def set_expiry(self, timeout):
@property
def ready(self):
"""Indicates whether the result has arrived"""
if self._is_ready:
if self._is_ready.is_set():
return True
if self._ttl.expired():
return False
self._conn.poll_all()
return self._is_ready
return self._is_ready.is_set()

@property
def error(self):
Expand All @@ -87,7 +88,7 @@ def error(self):
@property
def expired(self):
"""Indicates whether the AsyncResult has expired"""
return not self._is_ready and self._ttl.expired()
return not self._is_ready.is_set() and self._ttl.expired()

@property
def value(self):
Expand Down

0 comments on commit 5feb06c

Please sign in to comment.