def test_monitor_blocking(self): # Initially there's no active greenlet and no switches, # so nothing is considered blocked from gevent.events import subscribers from gevent.events import IEventLoopBlocked from zope.interface.verify import verifyObject events = [] subscribers.append(events.append) self.assertFalse(self.pmt.monitor_blocking(self.hub)) # Give it an active greenlet origin = object() target = object() self.pmt.greenlet_trace('switch', (origin, target)) # We've switched, so we're not blocked self.assertFalse(self.pmt.monitor_blocking(self.hub)) self.assertFalse(events) # Again without switching is a problem. self.assertTrue(self.pmt.monitor_blocking(self.hub)) self.assertTrue(events) verifyObject(IEventLoopBlocked, events[0]) del events[:] # But we can order it not to be a problem self.pmt.ignore_current_greenlet_blocking() self.assertFalse(self.pmt.monitor_blocking(self.hub)) self.assertFalse(events) # And back again self.pmt.monitor_current_greenlet_blocking() self.assertTrue(self.pmt.monitor_blocking(self.hub)) # A bad thread_ident in the hub doesn't mess things up self.hub.thread_ident = -1 self.assertTrue(self.pmt.monitor_blocking(self.hub))
def test_monitor_blocking(self): # Initially there's no active greenlet and no switches, # so nothing is considered blocked from gevent.events import subscribers from gevent.events import IEventLoopBlocked events = [] subscribers.append(events.append) self.assertFalse(self.pmt.monitor_blocking(self.hub)) # Give it an active greenlet origin = object() target = object() self.pmt._greenlet_tracer('switch', (origin, target)) # We've switched, so we're not blocked self.assertFalse(self.pmt.monitor_blocking(self.hub)) self.assertFalse(events) # Again without switching is a problem. self.assertTrue(self.pmt.monitor_blocking(self.hub)) self.assertTrue(events) verify.verifyObject(IEventLoopBlocked, events[0]) del events[:] # But we can order it not to be a problem self.pmt.ignore_current_greenlet_blocking() self.assertFalse(self.pmt.monitor_blocking(self.hub)) self.assertFalse(events) # And back again self.pmt.monitor_current_greenlet_blocking() self.assertTrue(self.pmt.monitor_blocking(self.hub)) # A bad thread_ident in the hub doesn't mess things up self.hub.thread_ident = -1 self.assertTrue(self.pmt.monitor_blocking(self.hub))