X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=id_generator.py;h=dc2ac9cc810a4e1d588d60231371e873d9d31966;hb=f2600f30801c849fc1d139386e3ddc3c9eb43e30;hp=bcd3a833270ffcd8f69f9c53f5a036d2c711566e;hpb=351e77c767c9084aa486eedbdc9902c635b06261;p=python_utils.git diff --git a/id_generator.py b/id_generator.py index bcd3a83..dc2ac9c 100644 --- a/id_generator.py +++ b/id_generator.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +"""A helper class for generating thread safe monotonically increasing +id numbers.""" + import itertools import logging @@ -28,10 +31,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()