Gary Benson: Python atomic counter
Do you need a thread-safe atomic counter in Python? Use itertools.count():
>>> from itertools import count
>>> counter = count()
>>> next(counter)
0
>>> next(counter)
1
>>> next(counter)
2
I found this in…