mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
PY-73549 Make initialization of variable handlers thread-safe
GitOrigin-RevId: eb4e0b566015efe92ed91604f20f38b64e74143b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
35fcc841c7
commit
fb6b4f42d4
@@ -1,4 +1,6 @@
|
|||||||
# Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
# Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
|
import threading
|
||||||
|
|
||||||
from _pydevd_bundle.pydevd_constants import RETURN_VALUES_DICT, dict_iter_items, \
|
from _pydevd_bundle.pydevd_constants import RETURN_VALUES_DICT, dict_iter_items, \
|
||||||
GET_FRAME_NORMAL_GROUP, GET_FRAME_SPECIAL_GROUP
|
GET_FRAME_NORMAL_GROUP, GET_FRAME_SPECIAL_GROUP
|
||||||
|
|
||||||
@@ -172,19 +174,36 @@ THRIFT_COMMUNICATION_VARS_HANDLER = 1
|
|||||||
|
|
||||||
|
|
||||||
class VarsHandlerContainer:
|
class VarsHandlerContainer:
|
||||||
_instance_xml_handler = None
|
instance_xml_handler = None
|
||||||
_instance_thrift_handler = None
|
instance_thrift_handler = None
|
||||||
|
|
||||||
|
|
||||||
|
_vars_handler_initialization_lock = threading.RLock()
|
||||||
|
|
||||||
|
|
||||||
|
def _init_xml_communication_vars_handler(func, handler_type):
|
||||||
|
with _vars_handler_initialization_lock:
|
||||||
|
if VarsHandlerContainer.instance_xml_handler is None:
|
||||||
|
VarsHandlerContainer.instance_xml_handler = \
|
||||||
|
VarsHandler(func, handler_type)
|
||||||
|
|
||||||
|
|
||||||
|
def _init_thrift_communication_var_handler(func, handler_type):
|
||||||
|
with _vars_handler_initialization_lock:
|
||||||
|
if VarsHandlerContainer.instance_thrift_handler is None:
|
||||||
|
VarsHandlerContainer.instance_thrift_handler = \
|
||||||
|
VarsHandler(func, handler_type)
|
||||||
|
|
||||||
|
|
||||||
def get_vars_handler(func, handler_type, group_type):
|
def get_vars_handler(func, handler_type, group_type):
|
||||||
if handler_type == XML_COMMUNICATION_VARS_HANDLER:
|
if handler_type == XML_COMMUNICATION_VARS_HANDLER:
|
||||||
if VarsHandlerContainer._instance_xml_handler is None:
|
if VarsHandlerContainer.instance_xml_handler is None:
|
||||||
VarsHandlerContainer._instance_xml_handler = VarsHandler(func, handler_type)
|
_init_xml_communication_vars_handler(func, handler_type)
|
||||||
return VarsHandlerContainer._instance_xml_handler.get_instance(group_type)
|
return VarsHandlerContainer.instance_xml_handler.get_instance(group_type)
|
||||||
elif handler_type == THRIFT_COMMUNICATION_VARS_HANDLER:
|
elif handler_type == THRIFT_COMMUNICATION_VARS_HANDLER:
|
||||||
if VarsHandlerContainer._instance_thrift_handler is None:
|
if VarsHandlerContainer.instance_thrift_handler is None:
|
||||||
VarsHandlerContainer._instance_thrift_handler = VarsHandler(func, handler_type)
|
_init_thrift_communication_var_handler(func, handler_type)
|
||||||
return VarsHandlerContainer._instance_thrift_handler.get_instance(group_type)
|
return VarsHandlerContainer.instance_thrift_handler.get_instance(group_type)
|
||||||
|
|
||||||
|
|
||||||
class VarsHandler:
|
class VarsHandler:
|
||||||
@@ -194,22 +213,32 @@ class VarsHandler:
|
|||||||
self._instance_special = None
|
self._instance_special = None
|
||||||
self._instance_return = None
|
self._instance_return = None
|
||||||
self.handler_type = handler_type
|
self.handler_type = handler_type
|
||||||
|
self._lock = threading.RLock()
|
||||||
|
|
||||||
def get_instance(self, group_type):
|
def get_instance(self, group_type):
|
||||||
if group_type == GET_FRAME_NORMAL_GROUP:
|
if group_type == GET_FRAME_NORMAL_GROUP:
|
||||||
if self._instance_normal is None:
|
if self._instance_normal is None:
|
||||||
self._init_normal()
|
with self._lock:
|
||||||
|
if self._instance_normal is None:
|
||||||
|
self._init_normal()
|
||||||
instance = self._instance_normal
|
instance = self._instance_normal
|
||||||
elif group_type == GET_FRAME_SPECIAL_GROUP:
|
elif group_type == GET_FRAME_SPECIAL_GROUP:
|
||||||
if self._instance_special is None:
|
if self._instance_special is None:
|
||||||
self._init_special()
|
with self._lock:
|
||||||
|
if self._instance_special is None:
|
||||||
|
self._init_special()
|
||||||
instance = self._instance_special
|
instance = self._instance_special
|
||||||
else:
|
else:
|
||||||
if self._instance_return is None:
|
if self._instance_return is None:
|
||||||
self._init_return()
|
with self._lock:
|
||||||
|
if self._instance_return is None:
|
||||||
|
self._init_return()
|
||||||
instance = self._instance_return
|
instance = self._instance_return
|
||||||
|
|
||||||
instance.update_handlers()
|
with self._lock:
|
||||||
|
if instance is not None:
|
||||||
|
instance.update_handlers()
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def _init_normal(self):
|
def _init_normal(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user