### Navigation

- index
- modules |
- modules |
- next |
- previous |
- homepage|
- search|
- documentation »
- toolbox - Toolbox of various functions and generic utilities »

# spacepy.toolbox.thread_map

`spacepy.toolbox.``thread_map`(target, iterable, thread_count=None, *args, **kwargs)

  Apply a function to every element of a list, in separate threads

  Interface is similar to multiprocessing.map, except it runs in threads

  Parameters: | target : callable Python callable to run on each element of iterable. For each call, an element of iterable is appended to args and both args and kwargs are passed through. Note that this means the iterable element is always the last positional argument; this allows the specification of self as the first argument for method calls. iterable : iterable elements to pass to each call of L{target} args : sequence arguments to pass to target before each element of iterable thread_count : integer Number of threads to spawn; see L{thread_job}. kwargs : dict keyword arguments to pass to L{target}.
  Returns: | out : list return values of L{target} for each item from L{iterable}

  Examples

  find totals of several arrays

      >>> import numpy
      >>> from spacepy import toolbox
      >>> inputs = range(100)
      >>> totals = toolbox.thread_map(numpy.sum, inputs)
      >>> print(totals[0], totals[50], totals[99])
      (0, 50, 99)

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- homepage|
- search|
- documentation »
- toolbox - Toolbox of various functions and generic utilities »