File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1212from common .cache .mem_cache import MemCache
1313
1414_lock = threading .Lock ()
15+ locks = {}
1516
1617
1718class ModelManage :
1819 cache = MemCache ('model' , {})
1920 up_clear_time = time .time ()
2021
22+ @staticmethod
23+ def _get_lock (_id ):
24+ lock = locks .get (_id )
25+ if lock is None :
26+ with _lock :
27+ lock = locks .get (_id )
28+ if lock is None :
29+ lock = threading .Lock ()
30+ locks [_id ] = lock
31+
32+ return lock
33+
2134 @staticmethod
2235 def get_model (_id , get_model ):
2336 model_instance = ModelManage .cache .get (_id )
2437 if model_instance is None :
25- with _lock :
38+ lock = ModelManage ._get_lock (_id )
39+ with lock :
2640 model_instance = ModelManage .cache .get (_id )
2741 if model_instance is None :
2842 model_instance = get_model (_id )
You can’t perform that action at this time.
0 commit comments