PyDocs

Nav

Concurrent Execution

serialize_iterator

threading

class · Added in 3.15 (source) not WASI
  • serialize_iterator(iterable)
Wrap a non-concurrent iterator with a lock to enforce sequential access.

Applies a non-reentrant lock around calls to __next__.  If the
wrapped iterator also defines send(), throw(), or close(), those
calls are serialized as well.

Allows iterator and generator instances to be shared by multiple consumer
threads.

For example, itertools.count does not make thread-safe instances,
but that is easily fixed with:

    atomic_counter = serialize_iterator(itertools.count())
0 Examples
No examples for threading/serialize_iterator.
See Also
No see-alsos for threading/serialize_iterator
0 Notes
No notes for serialize_iterator