Improved implentation of iterators in tpool; thanks to Slant
This commit is contained in:
4
AUTHORS
4
AUTHORS
@@ -44,4 +44,6 @@ Thanks To
|
||||
* Cesar Alaniz, for uncovering bugs of great import
|
||||
* the grugq, for contributing patches, suggestions, and use cases
|
||||
* Ralf Schmitt, for wsgi/webob incompatibility bug report and suggested fix
|
||||
* Benoit Chesneau, bug report on green.os and patch to fix it
|
||||
* Benoit Chesneau, bug report on green.os and patch to fix it
|
||||
* Slant, better iterator implementation in tpool
|
||||
* Ambroff, nice pygtk hub
|
||||
@@ -184,8 +184,6 @@ class Proxy(object):
|
||||
# the following are a buncha methods that the python interpeter
|
||||
# doesn't use getattr to retrieve and therefore have to be defined
|
||||
# explicitly
|
||||
def __iter__(self):
|
||||
return proxy_call(self._autowrap, self._obj.__iter__)
|
||||
def __getitem__(self, key):
|
||||
return proxy_call(self._autowrap, self._obj.__getitem__, key)
|
||||
def __setitem__(self, key, value):
|
||||
@@ -209,6 +207,13 @@ class Proxy(object):
|
||||
return len(self._obj)
|
||||
def __nonzero__(self):
|
||||
return bool(self._obj)
|
||||
def __iter__(self):
|
||||
if iter(self._obj) == self._obj:
|
||||
return self
|
||||
else:
|
||||
return Proxy(iter(self._obj))
|
||||
def next(self):
|
||||
return proxy_call(self._autowrap, self._obj.next)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -138,6 +138,30 @@ class TestTpool(LimitedTestCase):
|
||||
for i in prox:
|
||||
result.append(i)
|
||||
self.assertEquals(range(10), result)
|
||||
|
||||
@skip_with_pyevent
|
||||
def test_wrap_iterator2(self):
|
||||
def foo():
|
||||
import time
|
||||
for x in xrange(10):
|
||||
yield x
|
||||
time.sleep(0.01)
|
||||
|
||||
counter = [0]
|
||||
def tick():
|
||||
for i in xrange(100):
|
||||
counter[0]+=1
|
||||
eventlet.sleep(0.001)
|
||||
|
||||
gt = eventlet.spawn(tick)
|
||||
previtem = 0
|
||||
for item in tpool.Proxy(foo()):
|
||||
self.assert_(item >= previtem)
|
||||
# make sure the tick happened at least a few times so that we know
|
||||
# that our iterations in foo() were actually tpooled
|
||||
self.assert_(counter[0] > 10)
|
||||
gt.wait()
|
||||
|
||||
|
||||
@skip_with_pyevent
|
||||
def test_raising_exceptions(self):
|
||||
|
||||
Reference in New Issue
Block a user