Skip to content

Add thread-safe handler initialization using double-checked locking #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/spaceone/core/handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
import logging
import threading
from typing import List
from spaceone.core.base import CoreObject
from spaceone.core import config
Expand All @@ -25,6 +26,7 @@
"mutation": [],
"event": [],
}
_HANDLER_INIT_LOCK = threading.Lock()

_LOGGER = logging.getLogger(__name__)

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

def _check_init_state() -> None:
if not _HANDLER_INFO["init"]:
_init_handlers()
_HANDLER_INFO["init"] = True
with _HANDLER_INIT_LOCK:
if not _HANDLER_INFO["init"]:
_init_handlers()
_HANDLER_INFO["init"] = True
Loading