<!-- # hard line break macro for HTML -->

# fiftyone.core.map.threading

Threading mapping backend

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

**Classes:**

| [`ThreadMapper`](#fiftyone.core.map.threading.ThreadMapper)(batch_cls, num_workers[, ...])   | Executes map_samples with threading using iter_samples.   |
|----------------------------------------------------------------------------------------------|-----------------------------------------------------------|

### *class* fiftyone.core.map.threading.ThreadMapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: [`LocalMapper`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper)

Executes map_samples with threading using iter_samples.

**Methods:**

| [`create`](#fiftyone.core.map.threading.ThreadMapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|---------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.threading.ThreadMapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

**Attributes:**

| [`batch_size`](#fiftyone.core.map.threading.ThreadMapper.batch_size)   | Number of samples per worker batch   |
|------------------------------------------------------------------------|--------------------------------------|
| [`num_workers`](#fiftyone.core.map.threading.ThreadMapper.num_workers) | Number of workers to use             |

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int | None = None, batch_size: int | None = None, \*\*\_\_)

Create a new mapper instance

#### *property* batch_size *: int | None*

Number of samples per worker batch

#### map_samples(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

Applies map function to each sample and returns an iterator of the
results.

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection) *[**T* *]*) – The sample collection to
    map.
  * **map_fcn** (*Callable* *[* *[**Union* *[**T* *,* *U* *]* *]* *,* *R* *]*) – The map function to apply to
    each sample.
  * **iter_fcn** (*Callable* *[* *[**T* *]* *,* *U* *]*) – The function to iterate over the
    sample collection. If not provided the iteration function
    used is `iter_samples`.
  * **progress** (*Union* *[*[*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to save mutated samples mutated in
    the map function. Only valid when using the `iter_fcn` is None.
    Defaults to False.
  * **skip_failures** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *optional*) – Whether to gracefully continue
    without raising an error if the map function raises an exception
    for a sample. Defaults to True.
* **Yields:**
  *Iterator[Tuple[bson.ObjectId, R]]* –

  The sample ID and the result of
  : the map function for the sample.

#### *property* num_workers *: int*

Number of workers to use
