Commit 7c28916e authored by Arnaud Fontaine's avatar Arnaud Fontaine

Prevent other threads to create erp5.* packages and modules or seeing them incompletely loaded.

parent e695947f
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
from types import ModuleType from types import ModuleType
from . import aq_method_lock from . import aq_method_lock
import sys import sys
import imp
class PackageType(ModuleType): class PackageType(ModuleType):
""" """
...@@ -103,25 +104,19 @@ def initializeDynamicModules(): ...@@ -103,25 +104,19 @@ def initializeDynamicModules():
holds Live Test modules previously found in bt5 in $INSTANCE_HOME/test holds Live Test modules previously found in bt5 in $INSTANCE_HOME/test
""" """
erp5 = PackageType("erp5") erp5 = PackageType("erp5")
sys.modules["erp5"] = erp5
# Document classes without physical import path # Document classes without physical import path
erp5.document = ModuleType("erp5.document") erp5.document = ModuleType("erp5.document")
sys.modules["erp5.document"] = erp5.document
# Portal types as classes # Portal types as classes
from accessor_holder import AccessorHolderType, AccessorHolderModuleType from accessor_holder import AccessorHolderType, AccessorHolderModuleType
erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder") erp5.accessor_holder = AccessorHolderModuleType("erp5.accessor_holder")
erp5.accessor_holder.__path__ = [] erp5.accessor_holder.__path__ = []
sys.modules["erp5.accessor_holder"] = erp5.accessor_holder
erp5.accessor_holder.property_sheet = \ erp5.accessor_holder.property_sheet = \
AccessorHolderModuleType("erp5.accessor_holder.property_sheet") AccessorHolderModuleType("erp5.accessor_holder.property_sheet")
sys.modules["erp5.accessor_holder.property_sheet"] = \
erp5.accessor_holder.property_sheet
erp5.accessor_holder.portal_type = registerDynamicModule( erp5.accessor_holder.portal_type = registerDynamicModule(
'erp5.accessor_holder.portal_type', 'erp5.accessor_holder.portal_type',
AccessorHolderModuleType) AccessorHolderModuleType)
...@@ -136,10 +131,20 @@ def initializeDynamicModules(): ...@@ -136,10 +131,20 @@ def initializeDynamicModules():
# ZODB Components # ZODB Components
erp5.component = PackageType("erp5.component") erp5.component = PackageType("erp5.component")
sys.modules["erp5.component"] = erp5.component
from component_package import ComponentDynamicPackage from component_package import ComponentDynamicPackage
# Prevent other threads to create erp5.* packages and modules or seeing them
# incompletely
imp.acquire_lock()
try:
sys.modules["erp5"] = erp5
sys.modules["erp5.document"] = erp5.document
sys.modules["erp5.accessor_holder"] = erp5.accessor_holder
sys.modules["erp5.accessor_holder.property_sheet"] = \
erp5.accessor_holder.property_sheet
sys.modules["erp5.component"] = erp5.component
erp5.component.extension = ComponentDynamicPackage('erp5.component.extension', erp5.component.extension = ComponentDynamicPackage('erp5.component.extension',
'Extension Component') 'Extension Component')
...@@ -148,3 +153,5 @@ def initializeDynamicModules(): ...@@ -148,3 +153,5 @@ def initializeDynamicModules():
erp5.component.test = ComponentDynamicPackage('erp5.component.test', erp5.component.test = ComponentDynamicPackage('erp5.component.test',
'Test Component') 'Test Component')
finally:
imp.release_lock()
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