X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=id_generator.py;h=4b61a93081d6dd17ab341330e7d4f08991ad4aab;hb=3ca9b4d16433af8da5d2de7f4a2338b56b5428d5;hp=bcd3a833270ffcd8f69f9c53f5a036d2c711566e;hpb=351e77c767c9084aa486eedbdc9902c635b06261;p=python_utils.git diff --git a/id_generator.py b/id_generator.py index bcd3a83..4b61a93 100644 --- a/id_generator.py +++ b/id_generator.py @@ -1,5 +1,12 @@ #!/usr/bin/env python3 +# © Copyright 2021-2022, Scott Gasch + +"""A helper class for generating thread safe monotonically increasing +id numbers. + +""" + import itertools import logging @@ -12,7 +19,7 @@ generators = {} def get(name: str, *, start=0) -> int: """ - Returns a thread safe monotonically increasing id suitable for use + Returns a thread-safe, monotonically increasing id suitable for use as a globally unique identifier. >>> import id_generator @@ -28,10 +35,11 @@ def get(name: str, *, start=0) -> int: if name not in generators: generators[name] = itertools.count(start, 1) x = next(generators[name]) - logger.debug(f"Generated next id {x}") + logger.debug("Generated next id %d", x) return x if __name__ == '__main__': import doctest + doctest.testmod()