From e4aeadc730fe33360ceafe9d79b782d3a4f3e3cf Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 23 Jan 2009 15:20:18 +0600 Subject: [PATCH] hubs.switch: assert that the current greenlet is not the same as hub greenlet, otherwise weird things gonna happen --- eventlet/hubs/hub.py | 1 + eventlet/hubs/twistedr.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/eventlet/hubs/hub.py b/eventlet/hubs/hub.py index df3dc12..55de1d4 100644 --- a/eventlet/hubs/hub.py +++ b/eventlet/hubs/hub.py @@ -117,6 +117,7 @@ class BaseHub(object): def switch(self): cur = greenlet.getcurrent() + assert cur is not self.greenlet, 'Cannot switch to MAINLOOP from MAINLOOP' switch_out = getattr(cur, 'switch_out', None) if switch_out is not None: try: diff --git a/eventlet/hubs/twistedr.py b/eventlet/hubs/twistedr.py index 502985f..0540d89 100644 --- a/eventlet/hubs/twistedr.py +++ b/eventlet/hubs/twistedr.py @@ -109,10 +109,10 @@ class BaseTwistedHub(object): self.waiters_by_greenlet = {} def switch(self): - assert api.getcurrent() is not self.greenlet, 'Impossible to switch() from the mainloop greenlet' + assert api.getcurrent() is not self.greenlet, "Cannot switch from MAINLOOP to MAINLOOP" try: api.getcurrent().parent = self.greenlet - except ValueError, ex: + except ValueError: pass return self.greenlet.switch() @@ -217,11 +217,12 @@ class TwistedHub(BaseTwistedHub): BaseTwistedHub.__init__(self, g) def switch(self): + assert api.getcurrent() is not self.greenlet, "Cannot switch from MAINLOOP to MAINLOOP" if self.greenlet.dead: self.greenlet = api.Greenlet(self.run) try: api.getcurrent().parent = self.greenlet - except ValueError, ex: + except ValueError: pass return self.greenlet.switch()