Skip to content

Commit

Permalink
Hub: do not catch the error in switch_out(). Use switch_out to preven…
Browse files Browse the repository at this point in the history
…t Hub to Hub switch
  • Loading branch information
denik committed Aug 29, 2011
1 parent 7f5a562 commit 05fdc00
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions gevent/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,19 @@ def print_exception(self, context, type, value, tb):
sys.stderr.write('%s failed with %s\n\n' % (context, getattr(type, '__name__', 'exception'), ))

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]
try:
switch_out = getattr(cur, 'switch_out', None)
switch_out = getattr(getcurrent(), 'switch_out', None)
if switch_out is not None:
try:
switch_out()
except:
self.handle_error(switch_out, *sys.exc_info())
switch_out()
exc_clear()
return greenlet.switch(self)
finally:
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):
unique = object()
watcher.start(getcurrent().switch, unique)
Expand Down

0 comments on commit 05fdc00

Please sign in to comment.