File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 1- import logging
2- from functools import lru_cache
1+ from threading import Lock
32
4- from rich .console import Console
5- from rich .logging import RichHandler
63
7- console = Console (color_system = "256" , width = 200 , style = "blue" )
4+ class SingletonMeta (type ):
5+ """
6+ This is a thread-safe implementation of Singleton.
7+ """
88
9+ _instances = {}
910
10- @lru_cache
11- def get_logger (module_name ):
12- logger = logging .getLogger (module_name )
13- handler = RichHandler (
14- rich_tracebacks = True , console = console , tracebacks_show_locals = True
15- )
16- handler .setFormatter (
17- logging .Formatter ("[ %(threadName)s:%(funcName)s:%(lineno)d ] - %(message)s" )
18- )
19- logger .addHandler (handler )
20- logger .setLevel (logging .DEBUG )
21- return logger
11+ _lock : Lock = Lock ()
12+
13+ def __call__ (cls , * args , ** kwargs ):
14+ with cls ._lock :
15+ if cls not in cls ._instances :
16+ instance = super ().__call__ (* args , ** kwargs )
17+ cls ._instances [cls ] = instance
18+ return cls ._instances [cls ]
You can’t perform that action at this time.
0 commit comments