Пример #1
0
 def wait_for_change_q(change_q, count):
     @asyncio.coroutine
     def async_tests(change_q, count):
         r = []
         while len(r) < count:
             v = yield from change_q.get()
             r.append(v)
         return r
     try:
         r = asyncio.get_event_loop().run_until_complete(asyncio.wait_for(async_tests(change_q, count), timeout=5))
     except asyncio.TimeoutError:
         r = []
     return r
Пример #2
0
 def wait_for_change_q(block_chain, count):
     r = []
     done = asyncio.Future()
     def change_callback(blockchain, ops):
         r.extend(ops)
         if len(r) >= count:
             done.set_result(r)
     block_chain.add_change_callback(change_callback)
     try:
         r = asyncio.get_event_loop().run_until_complete(asyncio.wait_for(done, timeout=5))
     except asyncio.TimeoutError:
         r = []
     return r
Пример #3
0
    def wait_for_change_q(change_q, count):
        @asyncio.coroutine
        def async_tests(change_q, count):
            r = []
            while len(r) < count:
                v = yield from change_q.get()
                r.append(v)
            return r

        try:
            r = asyncio.get_event_loop().run_until_complete(
                asyncio.wait_for(async_tests(change_q, count), timeout=5))
        except asyncio.TimeoutError:
            r = []
        return r
Пример #4
0
 def run_local_peer(peer_list):
     inv_collector = InvCollector()
     for peer in peer_list:
         inv_collector.add_peer(peer)
     r = []
     inv_item_q = inv_collector.new_inv_item_queue()
     while len(r) < 5:
         yield from asyncio.sleep(0.1)
         inv_item = yield from inv_item_q.get()
         try:
             v = yield from asyncio.wait_for(inv_collector.fetch(inv_item), timeout=0.5)
             if v:
                 r.append(v)
         except asyncio.TimeoutError:
             pass
     return r
Пример #5
0
    def wait_for_change_q(block_chain, count):
        r = []
        done = asyncio.Future()

        def change_callback(blockchain, ops):
            r.extend(ops)
            if len(r) >= count:
                done.set_result(r)

        block_chain.add_change_callback(change_callback)
        try:
            r = asyncio.get_event_loop().run_until_complete(
                asyncio.wait_for(done, timeout=5))
        except asyncio.TimeoutError:
            r = []
        return r