Example #1
0
def send_stream(item_group, stream, num_heaps):
    tasks = []
    for i in range(num_heaps + 1):
        if i == num_heaps:
            heap = item_group.get_end()
        else:
            heap = item_group.get_heap(data="all")
        task = trollius.async(stream.async_send_heap(heap))
        tasks.append(task)
    yield From(trollius.wait(tasks))
    transferred = 0
    for task in tasks:
        transferred += task.result()
    raise Return(transferred)
Example #2
0
        stream = make_stream(sources)
        return run_stream(stream, sources[0], args)

    args = get_args()
    logging.basicConfig(level=getattr(logging, args.log.upper()))

    if args.affinity is not None and len(args.affinity) > 0:
        spead2.ThreadPool.set_affinity(args.affinity[0])
        thread_pool = spead2.ThreadPool(args.threads,
                                        args.affinity[1:] + args.affinity[:1])
    else:
        thread_pool = spead2.ThreadPool(args.threads)
    memory_pool = None
    if args.mem_pool:
        memory_pool = spead2.MemoryPool(args.mem_lower, args.mem_upper,
                                        args.mem_max_free, args.mem_initial)
    if args.joint:
        coros = [make_coro(args.source)]
    else:
        coros = [make_coro([source]) for source in args.source]
    tasks = [trollius. async (x) for x in coros]
    task = trollius.wait(tasks, return_when=trollius.FIRST_EXCEPTION)
    trollius.get_event_loop().run_until_complete(task)
    # Trigger any recorded exception
    for t in tasks:
        t.result()


if __name__ == '__main__':
    main()
Example #3
0
        return stream

    def make_coro(sources):
        stream = make_stream(sources)
        return run_stream(stream, sources[0], args)

    args = get_args()
    logging.basicConfig(level=getattr(logging, args.log.upper()))

    if args.affinity is not None and len(args.affinity) > 0:
        spead2.ThreadPool.set_affinity(args.affinity[0])
        thread_pool = spead2.ThreadPool(args.threads, args.affinity[1:] + args.affinity[:1])
    else:
        thread_pool = spead2.ThreadPool(args.threads)
    memory_pool = None
    if args.mem_pool:
        memory_pool = spead2.MemoryPool(args.mem_lower, args.mem_upper, args.mem_max_free, args.mem_initial)
    if args.joint:
        coros = [make_coro(args.source)]
    else:
        coros = [make_coro([source]) for source in args.source]
    tasks = [trollius.async(x) for x in coros]
    task = trollius.wait(tasks, return_when=trollius.FIRST_EXCEPTION)
    trollius.get_event_loop().run_until_complete(task)
    # Trigger any recorded exception
    for t in tasks:
        t.result()

if __name__ == '__main__':
    main()