This is thread-safe:
from threading import Lock
lock = Lock() counter = 0 def get_next(): with lock: global counter counter += 1 my_counter = counter
This is a great workaround. I can try to improve this. But first of all should we depend on the user to do this locking? I don't think so. So is it possible to implement this in the background without affecting current performance?