From: Mike Bayer Date: Wed, 19 Feb 2014 21:12:36 +0000 (-0500) Subject: restore check ahead of the lock to avoid locking when not needed X-Git-Tag: rel_0_8_5~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f9059f6cd8ccd9f50a9398f495fac89c85a83c29;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git restore check ahead of the lock to avoid locking when not needed --- diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index ec8481caf3..ab25c660f3 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -394,12 +394,13 @@ class _CompoundListener(object): """Execute this event, but only if it has not been executed already for this collection.""" - with self._exec_once_mutex: - if not self._exec_once: - try: - self(*args, **kw) - finally: - self._exec_once = True + if not self._exec_once: + with self._exec_once_mutex: + if not self._exec_once: + try: + self(*args, **kw) + finally: + self._exec_once = True # I'm not entirely thrilled about the overhead here,