(process_func, iterables, max_batch_size, batch_type, **kwargs)
| 525 | |
| 526 | |
| 527 | def _process_iterable(process_func, iterables, max_batch_size, batch_type, **kwargs): |
| 528 | if max_batch_size < 1: |
| 529 | raise ValueError("max_batch_size must be >= 1") |
| 530 | |
| 531 | if len(iterables) == 1: |
| 532 | iterable = iterables[0] |
| 533 | else: |
| 534 | iterable = itertools.zip_longest(*iterables) |
| 535 | |
| 536 | kwargs.update( |
| 537 | { |
| 538 | "max_batch_size": max_batch_size, |
| 539 | "batch_type": batch_type, |
| 540 | "asynchronous": True, |
| 541 | } |
| 542 | ) |
| 543 | |
| 544 | read_batch_size = max_batch_size * 16 if max_batch_size > 1 else max_batch_size |
| 545 | queue = collections.deque() |
| 546 | |
| 547 | for streams in _batch_iterator(iterable, read_batch_size, batch_type): |
| 548 | queue.extend(process_func(*streams, **kwargs)) |
| 549 | |
| 550 | while queue and queue[0].done(): |
| 551 | yield queue.popleft().result() |
| 552 | |
| 553 | while queue: |
| 554 | yield queue.popleft().result() |
| 555 | |
| 556 | |
| 557 | def _batch_iterator(iterable, batch_size, batch_type): |
no test coverage detected