MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _extract_parallel

Function _extract_parallel

graphify/extract.py:12751–12891  ·  view source on GitHub ↗

Extract uncached files in parallel using ProcessPoolExecutor. Returns True if the pool ran to completion. Returns False if the pool failed in a recoverable way (typically Windows-spawn without an ``if __name__ == "__main__"`` guard in the calling script, which causes BrokenProcessPo

(
    uncached_work: list[tuple[int, Path]],
    per_file: list[dict | None],
    root: Path,
    max_workers: int | None,
    total_files: int,
    cache_location: Path | None = None,
    *,
    refresh_astro_cache: bool = False,
    refresh_paths: "frozenset[str]" = frozenset(),
)

Source from the content-addressed store, hash-verified

12749
12750
12751def _extract_parallel(
12752 uncached_work: list[tuple[int, Path]],
12753 per_file: list[dict | None],
12754 root: Path,
12755 max_workers: int | None,
12756 total_files: int,
12757 cache_location: Path | None = None,
12758 *,
12759 refresh_astro_cache: bool = False,
12760 refresh_paths: "frozenset[str]" = frozenset(),
12761) -> bool:
12762 """Extract uncached files in parallel using ProcessPoolExecutor.
12763
12764 Returns True if the pool ran to completion. Returns False if the pool
12765 failed in a recoverable way (typically Windows-spawn without an
12766 ``if __name__ == "__main__"`` guard in the calling script, which causes
12767 BrokenProcessPool); the caller should fall back to sequential extraction.
12768 """
12769 import concurrent.futures
12770
12771 if max_workers is None:
12772 max_workers = _default_max_workers(uncached_work)
12773
12774 # Windows ProcessPoolExecutor hard-caps at 61 workers (CPython limitation
12775 # tied to WaitForMultipleObjects). Clamp here so every path — auto-compute,
12776 # GRAPHIFY_MAX_WORKERS, and --max-workers — stays valid on >61-core boxes
12777 # (issue #1298). Guard against 0 from an empty work list.
12778 if sys.platform == "win32":
12779 max_workers = min(max_workers, 61)
12780 max_workers = max(max_workers, 1)
12781
12782 # A one-worker pool buys no parallelism: it still pays process spawn plus an
12783 # IPC round trip per file, and it is the one residual case where the parent's
12784 # rebuild watchdog (os._exit) can orphan a worker that is mid-task. The
12785 # Windows post-commit hook exports GRAPHIFY_MAX_WORKERS=1, so this is the
12786 # default there. Hand the work back so the caller extracts sequentially in
12787 # this process instead (#2173).
12788 if max_workers == 1:
12789 return False
12790
12791 # root anchors hash keys / node ids / XAML boundary; cache_location is where
12792 # the cache dir is written (defaults to root when not decoupled) (#1774).
12793 root_str = str(root)
12794 cache_loc_str = str(cache_location if cache_location is not None else root)
12795 work_items = [(idx, str(path), root_str, cache_loc_str) for idx, path in uncached_work]
12796 extract_file: Callable[[tuple], tuple[int, dict]] = _extract_single_file
12797 if refresh_astro_cache or refresh_paths:
12798 from functools import partial
12799 extract_file = partial(
12800 _extract_single_file,
12801 refresh_astro_cache=refresh_astro_cache,
12802 refresh_paths=refresh_paths,
12803 )
12804
12805 done_count = 0
12806 failed: list[int] = [] # positions into uncached_work whose future failed
12807 _PROGRESS_INTERVAL = 100
12808 try:

Callers 1

extractFunction · 0.85

Calls 5

get_language_overridesFunction · 0.90
_default_max_workersFunction · 0.85
_extract_sequentialFunction · 0.85
submitMethod · 0.80
resultMethod · 0.45

Tested by

no test coverage detected