(method_name: callable, items: list, **kwargs)
| 28 | |
| 29 | |
| 30 | def parse_with_workers(method_name: callable, items: list, **kwargs): |
| 31 | workers = 10 # should be a config value |
| 32 | |
| 33 | logger.info(f'Parsing {len(items)} documents using {method} (with {workers} workers)...') |
| 34 | |
| 35 | with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor: |
| 36 | futures = [] |
| 37 | for i in range(workers): |
| 38 | futures.append(executor.submit(_wrap_with_try_except(method), items[i::workers], **kwargs)) |
| 39 | concurrent.futures.wait(futures) |
| 40 | for w in futures: |
| 41 | e = w.exception() |
| 42 | if e: |
| 43 | logging.exception("Worker failed", exc_info=e) |
| 44 | |
| 45 | |
| 46 | @lru_cache(maxsize=512) |
nothing calls this directly
no test coverage detected