Commit 87aba4ec authored by Nicolas Dumazet's avatar Nicolas Dumazet

use lock to avoid reloading portal type classes in one thread while

the other one loads them


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40754 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c89481d7
......@@ -159,34 +159,38 @@ class PortalTypeMetaClass(ExtensionClass):
raise AttributeError("Could not find a portal type class in"
" class hierarchy")
ERP5Base.aq_method_lock.acquire()
portal_type = klass.__name__
try:
class_definition = generatePortalTypeClass(portal_type)
except AttributeError:
LOG("ERP5Type.Dynamic", WARNING,
"Could not access Portal Type Object for type %r"
% portal_type, error=sys.exc_info())
base_list = (ERP5BaseBroken, )
attribute_dict = {}
interface_list = []
else:
base_list, interface_list, attribute_dict = class_definition
# save the old bases to be able to restore a ghost state later
if klass.__ghostbase__ is None:
# but only do it if we're in the innermost call, otherwise
# klass.__bases__ might just be the Document without accessor
# holders, and we would override the real ghost class
klass.__ghostbase__ = klass.__bases__
klass.__bases__ = base_list
for key, value in attribute_dict.iteritems():
setattr(klass, key, value)
klass.resetAcquisitionAndSecurity()
for interface in interface_list:
classImplements(klass, interface)
try:
class_definition = generatePortalTypeClass(portal_type)
except AttributeError:
LOG("ERP5Type.Dynamic", WARNING,
"Could not access Portal Type Object for type %r"
% portal_type, error=sys.exc_info())
base_list = (ERP5BaseBroken, )
attribute_dict = {}
interface_list = []
else:
base_list, interface_list, attribute_dict = class_definition
# save the old bases to be able to restore a ghost state later
if klass.__ghostbase__ is None:
# but only do it if we're in the innermost call, otherwise
# klass.__bases__ might just be the Document without accessor
# holders, and we would override the real ghost class
klass.__ghostbase__ = klass.__bases__
klass.__bases__ = base_list
for key, value in attribute_dict.iteritems():
setattr(klass, key, value)
klass.resetAcquisitionAndSecurity()
for interface in interface_list:
classImplements(klass, interface)
finally:
ERP5Base.aq_method_lock.release()
def generateLazyPortalTypeClass(portal_type_name):
return PortalTypeMetaClass(portal_type_name, (GhostPortalType,), {})
......@@ -33,7 +33,7 @@ from types import ModuleType
from dynamic_module import registerDynamicModule
from Products.ERP5Type.Base import _aq_reset
from Products.ERP5Type.Base import _aq_reset, Base
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type.Utils import setDefaultClassProperties
from Products.ERP5Type import document_class_registry, mixin_class_registry
......@@ -371,9 +371,13 @@ def synchronizeDynamicModules(context, force=False):
import erp5
for class_name, klass in inspect.getmembers(erp5.portal_type,
inspect.isclass):
klass.restoreGhostState()
Base.aq_method_lock.acquire()
try:
for class_name, klass in inspect.getmembers(erp5.portal_type,
inspect.isclass):
klass.restoreGhostState()
finally:
Base.aq_method_lock.release()
# Clear accessor holders of ZODB Property Sheets
for property_sheet_id in erp5.accessor_holder.__dict__.keys():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment