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 12
12
from common .cache .mem_cache import MemCache
13
13
14
14
_lock = threading .Lock ()
15
+ locks = {}
15
16
16
17
17
18
class ModelManage :
18
19
cache = MemCache ('model' , {})
19
20
up_clear_time = time .time ()
20
21
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
+
21
34
@staticmethod
22
35
def get_model (_id , get_model ):
23
36
model_instance = ModelManage .cache .get (_id )
24
37
if model_instance is None :
25
- with _lock :
38
+ lock = ModelManage ._get_lock (_id )
39
+ with lock :
26
40
model_instance = ModelManage .cache .get (_id )
27
41
if model_instance is None :
28
42
model_instance = get_model (_id )
You can’t perform that action at this time.
0 commit comments