Skip to content

Commit 3671e68

Browse files
committed
feat: add thread-safe handler initialization using double-checked locking
Signed-off-by: ImMin5 <mino@megazone.com>
1 parent 821f422 commit 3671e68

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/spaceone/core/handler/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import abc
22
import logging
3+
import threading
34
from typing import List
45
from spaceone.core.base import CoreObject
56
from spaceone.core import config
@@ -25,6 +26,7 @@
2526
"mutation": [],
2627
"event": [],
2728
}
29+
_HANDLER_THREAD_LOCK = threading.Lock()
2830

2931
_LOGGER = logging.getLogger(__name__)
3032

@@ -145,5 +147,7 @@ def get_event_handlers() -> List[BaseEventHandler]:
145147

146148
def _check_init_state() -> None:
147149
if not _HANDLER_INFO["init"]:
148-
_init_handlers()
149-
_HANDLER_INFO["init"] = True
150+
with _HANDLER_THREAD_LOCK:
151+
if not _HANDLER_INFO["init"]:
152+
_init_handlers()
153+
_HANDLER_INFO["init"] = True

0 commit comments

Comments
 (0)