diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/orm/__init__.py | 34 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 6 |
2 files changed, 26 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 7a73ecca5..36830e861 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -117,12 +117,16 @@ def clear_mappers(): classes as their primary mapper. """ - for mapper in mapper_registry.values(): - attribute_manager.reset_class_managed(mapper.class_) - if hasattr(mapper.class_, 'c'): - del mapper.class_.c - mapper_registry.clear() - sautil.ArgSingleton.instances.clear() + mapperlib._COMPILE_MUTEX.acquire() + try: + for mapper in mapper_registry.values(): + attribute_manager.reset_class_managed(mapper.class_) + if hasattr(mapper.class_, 'c'): + del mapper.class_.c + mapper_registry.clear() + sautil.ArgSingleton.instances.clear() + finally: + mapperlib._COMPILE_MUTEX.release() def clear_mapper(m): """Remove the given mapper from the storage of mappers. @@ -130,13 +134,17 @@ def clear_mapper(m): When a new mapper is created for the previous mapper's class, it will be used as that classes' new primary mapper. """ - - del mapper_registry[m.class_key] - attribute_manager.reset_class_managed(m.class_) - if hasattr(m.class_, 'c'): - del m.class_.c - m.class_key.dispose() - + + mapperlib._COMPILE_MUTEX.acquire() + try: + del mapper_registry[m.class_key] + attribute_manager.reset_class_managed(m.class_) + if hasattr(m.class_, 'c'): + del m.class_.c + m.class_key.dispose() + finally: + mapperlib._COMPILE_MUTEX.release() + def extension(ext): """Return a ``MapperOption`` that will insert the given ``MapperExtension`` to the beginning of the list of extensions diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 7e44d8a42..994264cc7 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -687,7 +687,11 @@ class Mapper(object): # cant set __name__ in py 2.3 ! pass self.class_.__init__ = init - mapper_registry[self.class_key] = self + _COMPILE_MUTEX.acquire() + try: + mapper_registry[self.class_key] = self + finally: + _COMPILE_MUTEX.release() if self.entity_name is None: self.class_.c = self.c |