Commit acd98e9d authored by Denis Bilenko's avatar Denis Bilenko

hub.py: avoid AttributeError in Waiter

it could be that self.greenlet was reset to None by the time handle_error is called
parent c77031c9
...@@ -537,29 +537,33 @@ class Waiter(object): ...@@ -537,29 +537,33 @@ class Waiter(object):
def switch(self, value=None): def switch(self, value=None):
"""Switch to the greenlet if one's available. Otherwise store the value.""" """Switch to the greenlet if one's available. Otherwise store the value."""
if self.greenlet is None: greenlet = self.greenlet
if greenlet is None:
self.value = value self.value = value
self._exception = None self._exception = None
else: else:
assert getcurrent() is self.hub, "Can only use Waiter.switch method from the Hub greenlet" assert getcurrent() is self.hub, "Can only use Waiter.switch method from the Hub greenlet"
switch = greenlet.switch
try: try:
self.greenlet.switch(value) switch(value)
except: except:
self.hub.handle_error(self.greenlet.switch, *sys.exc_info()) self.hub.handle_error(switch, *sys.exc_info())
def switch_args(self, *args): def switch_args(self, *args):
return self.switch(args) return self.switch(args)
def throw(self, *throw_args): def throw(self, *throw_args):
"""Switch to the greenlet with the exception. If there's no greenlet, store the exception.""" """Switch to the greenlet with the exception. If there's no greenlet, store the exception."""
if self.greenlet is None: greenlet = self.greenlet
if greenlet is None:
self._exception = throw_args self._exception = throw_args
else: else:
assert getcurrent() is self.hub, "Can only use Waiter.switch method from the Hub greenlet" assert getcurrent() is self.hub, "Can only use Waiter.switch method from the Hub greenlet"
throw = greenlet.throw
try: try:
self.greenlet.throw(*throw_args) throw(*throw_args)
except: except:
self.hub.handle_error(self.greenlet.throw, *sys.exc_info()) self.hub.handle_error(throw, *sys.exc_info())
def get(self): def get(self):
"""If a value/an exception is stored, return/raise it. Otherwise until switch() or throw() is called.""" """If a value/an exception is stored, return/raise it. Otherwise until switch() or throw() is called."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment