3 """A helper class for generating thread safe monotonically increasing
9 # This module is commonly used by others in here and should avoid
10 # taking any unnecessary dependencies back on them.
12 logger = logging.getLogger(__name__)
16 def get(name: str, *, start=0) -> int:
18 Returns a thread safe monotonically increasing id suitable for use
19 as a globally unique identifier.
21 >>> import id_generator
22 >>> id_generator.get('student_id')
24 >>> id_generator.get('student_id')
26 >>> id_generator.get('employee_id', start=10000)
28 >>> id_generator.get('employee_id', start=10000)
31 if name not in generators:
32 generators[name] = itertools.count(start, 1)
33 x = next(generators[name])
34 logger.debug("Generated next id %d", x)
38 if __name__ == '__main__':