diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-19 10:48:32 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-19 10:48:32 -0500 |
| commit | dd32540dabbee0678530fb1b0868d1eb41572dca (patch) | |
| tree | 52f11b69d3639762d52c83c7482efb8a79f368d0 /lib/sqlalchemy/event | |
| parent | 185938e7b7467a364fc8df5bee2597b4fee91bac (diff) | |
| download | sqlalchemy-dd32540dabbee0678530fb1b0868d1eb41572dca.tar.gz | |
- Fixed a critical regression caused by :ticket:`2880` where the newly
concurrent ability to return connections from the pool means that the
"first_connect" event is now no longer synchronized either, thus leading
to dialect mis-configurations under even minimal concurrency situations.
Diffstat (limited to 'lib/sqlalchemy/event')
| -rw-r--r-- | lib/sqlalchemy/event/attr.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sqlalchemy/event/attr.py b/lib/sqlalchemy/event/attr.py index 3f8947546..ca94493f5 100644 --- a/lib/sqlalchemy/event/attr.py +++ b/lib/sqlalchemy/event/attr.py @@ -28,14 +28,16 @@ as well as support for subclass propagation (e.g. events assigned to """ -from __future__ import absolute_import +from __future__ import absolute_import, with_statement from .. import util +from ..util import threading from . import registry from . import legacy from itertools import chain import weakref + class RefCollection(object): @util.memoized_property def ref(self): @@ -230,13 +232,20 @@ class _EmptyListener(_HasParentDispatchDescriptor): class _CompoundListener(_HasParentDispatchDescriptor): _exec_once = False + @util.memoized_property + def _exec_once_mutex(self): + return threading.Lock() + def exec_once(self, *args, **kw): """Execute this event, but only if it has not been executed already for this collection.""" - if not self._exec_once: - self(*args, **kw) - self._exec_once = True + with self._exec_once_mutex: + if not self._exec_once: + try: + self(*args, **kw) + finally: + self._exec_once = True def __call__(self, *args, **kw): """Execute this event.""" |
