Wrap an iterator-returning callable to make its iterators thread-safe.
Existing itertools and more-itertools can be wrapped so that their
iterator instances are serialized.
For example, itertools.count does not make thread-safe instances,
but that is easily fixed with:
atomic_counter = synchronized_iterator(itertools.count)
Can also be used as a decorator for generator function definitions
so that the generator instances are serialized::
import time
@synchronized_iterator
def enumerate_and_timestamp(iterable):
for count, value in enumerate(iterable):
yield count, time.time_ns(), value