{"record":{"id":"caf15276f9ebbc26","repo":"roboflow/supervision","slug":"thread-workers-must-be-a-positive-integer-recei","errorCode":null,"errorMessage":"`thread_workers` must be a positive integer. Received: {thread_workers}","messagePattern":"`thread_workers` must be a positive integer\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/tools/inference_slicer.py","lineNumber":283,"sourceCode":"            Callable[[ImageType], Detections]\n            | Callable[[list[npt.NDArray[Any]]], list[Detections]]\n        ),\n        slice_wh: int | tuple[int, int] = 640,\n        overlap_wh: int | tuple[int, int] = 100,\n        overlap_filter: OverlapFilter | str = OverlapFilter.NON_MAX_SUPPRESSION,\n        iou_threshold: float = 0.5,\n        overlap_metric: OverlapMetric | str = OverlapMetric.IOU,\n        thread_workers: int = 1,\n        compact_masks: bool = False,\n        batch_size: int = 1,\n    ):\n        slice_wh_norm = self._normalize_slice_wh(slice_wh)\n        overlap_wh_norm = self._normalize_overlap_wh(overlap_wh)\n\n        self._validate_overlap(slice_wh=slice_wh_norm, overlap_wh=overlap_wh_norm)\n\n        if thread_workers < 1:\n            raise ValueError(\n                \"`thread_workers` must be a positive integer. \"\n                f\"Received: {thread_workers}\"\n            )\n        if batch_size < 1:\n            raise ValueError(\n                f\"`batch_size` must be a positive integer. Received: {batch_size}\"\n            )\n\n        self.slice_wh = slice_wh_norm\n        self.overlap_wh = overlap_wh_norm\n        self.iou_threshold = iou_threshold\n        self.overlap_metric = OverlapMetric.from_value(overlap_metric)\n        self.overlap_filter = OverlapFilter.from_value(overlap_filter)\n        # Stored as single-image type; batch path calls with list[ndarray] via\n        # _run_callback_batch which suppresses the arg-type mismatch there.\n        self.callback: Callable[[npt.NDArray[Any]], Detections] = callback  # type: ignore[assignment]\n        self.thread_workers = thread_workers\n        self.compact_masks = compact_masks","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/tools/inference_slicer.py#L265-L301","documentation":"Raised by InferenceSlicer.__init__ when thread_workers is less than 1. thread_workers sets how many worker threads execute slice inference concurrently; zero or negative workers is not a meaningful thread-pool size, so construction fails.","triggerScenarios":"Constructing sv.InferenceSlicer(callback=..., thread_workers=0) or a negative value, often from a formula such as os.cpu_count() - N that underflows on small machines (cpu_count() returning 1).","commonSituations":"Sizing workers from CPU count with an subtraction that can hit 0 in containers or CI runners restricted to one core; config defaults left at 0 meaning 'auto' in other libraries.","solutions":["Use a positive integer, e.g. thread_workers=4, or keep the default of 1 for sequential slicing.","Guard dynamic sizing: max(1, (os.cpu_count() or 1) - 1).","Treat 0 not as 'auto' here — supervision has no auto mode for this parameter."],"exampleFix":"# before\nslicer = sv.InferenceSlicer(callback=cb, thread_workers=os.cpu_count() - 4)  # 0 on a 4-core-limited CI runner\n\n# after\nslicer = sv.InferenceSlicer(callback=cb, thread_workers=max(1, (os.cpu_count() or 1) - 4))","handlingStrategy":"validation","validationCode":"import os\nworkers = max(1, int(cfg.get('thread_workers', 1)) or 1)\nslicer = sv.InferenceSlicer(callback=cb, thread_workers=workers)","typeGuard":"def is_valid_thread_workers(v) -> bool:\n    return isinstance(v, int) and v >= 1","tryCatchPattern":null,"preventionTips":["Clamp CPU-derived worker counts with max(1, ...).","Do not reuse the '0 means auto' convention from other libraries here."],"tags":["inference-slicer","threading","configuration","validation","valueerror"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}