import itertools
import logging
+# This module is commonly used by others in here and should avoid
+# taking any unnecessary dependencies back on them.
+
logger = logging.getLogger(__name__)
generators = {}
def get(name: str) -> int:
"""
- def __init__(self):
- self.my_unique_id = id_generator.get("student_id")
+ Returns a thread safe monotonically increasing id suitable for use
+ as a globally unique identifier.
+
+ >>> import id_generator
+ >>> id_generator.get('student_id')
+ 0
+ >>> id_generator.get('student_id')
+ 1
"""
if name not in generators:
generators[name] = itertools.count()
x = next(generators[name])
logger.debug(f"Generated next id {x}")
return x
+
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()