Commit 05fdc001 authored by Denis Bilenko's avatar Denis Bilenko

Hub: do not catch the error in switch_out(). Use switch_out to prevent Hub to Hub switch

parent 7f5a562b
...@@ -277,21 +277,19 @@ class Hub(greenlet): ...@@ -277,21 +277,19 @@ class Hub(greenlet):
sys.stderr.write('%s failed with %s\n\n' % (context, getattr(type, '__name__', 'exception'), )) sys.stderr.write('%s failed with %s\n\n' % (context, getattr(type, '__name__', 'exception'), ))
def switch(self): def switch(self):
cur = getcurrent()
assert cur is not self, 'Impossible to call blocking function in the event loop callback'
exc_type, exc_value = sys.exc_info()[:2] exc_type, exc_value = sys.exc_info()[:2]
try: try:
switch_out = getattr(cur, 'switch_out', None) switch_out = getattr(getcurrent(), 'switch_out', None)
if switch_out is not None: if switch_out is not None:
try:
switch_out() switch_out()
except:
self.handle_error(switch_out, *sys.exc_info())
exc_clear() exc_clear()
return greenlet.switch(self) return greenlet.switch(self)
finally: finally:
core.set_exc_info(exc_type, exc_value) core.set_exc_info(exc_type, exc_value)
def switch_out(self):
raise AssertionError('Impossible to call blocking function in the event loop callback')
def wait(self, watcher): def wait(self, watcher):
unique = object() unique = object()
watcher.start(getcurrent().switch, unique) watcher.start(getcurrent().switch, unique)
......
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