issue #446: update Receiver.__iter__ to match
iter() previously relied on the fake dead message being enqueued.
This commit is contained in:
parent
386d869d5f
commit
822978520f
|
@ -894,8 +894,9 @@ class Receiver(object):
|
|||
until :class:`ChannelError` is raised.
|
||||
"""
|
||||
while True:
|
||||
msg = self.get(throw_dead=False)
|
||||
if msg.is_dead:
|
||||
try:
|
||||
msg = self.get()
|
||||
except ChannelError:
|
||||
return
|
||||
yield msg
|
||||
|
||||
|
|
|
@ -37,6 +37,27 @@ class IterationTest(testlib.RouterMixin, testlib.TestCase):
|
|||
self.assertEquals(list(range(5)), list(m.unpickle() for m in recv))
|
||||
self.assertEquals(10, ret.get().unpickle())
|
||||
|
||||
def iter_and_put(self, recv, latch):
|
||||
try:
|
||||
for msg in recv:
|
||||
latch.put(msg)
|
||||
except Exception:
|
||||
latch.put(sys.exc_info()[1])
|
||||
|
||||
def test_close_stops_iteration(self):
|
||||
recv = mitogen.core.Receiver(self.router)
|
||||
latch = mitogen.core.Latch()
|
||||
t = threading.Thread(
|
||||
target=self.iter_and_put,
|
||||
args=(recv, latch),
|
||||
)
|
||||
t.start()
|
||||
t.join(0.1)
|
||||
recv.close()
|
||||
t.join()
|
||||
self.assertTrue(latch.empty())
|
||||
|
||||
|
||||
|
||||
class CloseTest(testlib.RouterMixin, testlib.TestCase):
|
||||
def wait(self, latch, wait_recv):
|
||||
|
|
Loading…
Reference in New Issue