def test_channel_callback_stays_active(self, earlyfree=True): |
|
l = [] |
channel = self.gw.remote_exec(source=''' |
import thread, time |
def producer(subchannel): |
for i in range(5): |
time.sleep(0.15) |
subchannel.send(i*100) |
channel2 = channel.receive() |
thread.start_new_thread(producer, (channel2,)) |
del channel2 |
''') |
subchannel = self.gw.newchannel() |
subchannel.setcallback(l.append) |
-> channel.send(subchannel) |
if earlyfree: |
subchannel = None |
counter = 100 |
while len(l) < 5: |
if subchannel and subchannel.isclosed(): |
break |
counter -= 1 |
print counter |
if not counter: |
py.test.fail("timed out waiting for the answer[%d]" % len(l)) |
time.sleep(0.04) |
assert l == [0, 100, 200, 300, 400] |
return subchannel |