summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/event/api.py14
-rw-r--r--lib/sqlalchemy/util/langhelpers.py3
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/event/api.py b/lib/sqlalchemy/event/api.py
index e7c30901f..260d6e86f 100644
--- a/lib/sqlalchemy/event/api.py
+++ b/lib/sqlalchemy/event/api.py
@@ -64,6 +64,13 @@ def listen(target, identifier, fn, *args, **kw):
.. versionadded:: 0.9.4 Added ``once=True`` to :func:`.event.listen`
and :func:`.event.listens_for`.
+ .. warning:: The ``once`` argument does not imply automatic de-registration
+ of the listener function after it has been invoked a first time; a
+ listener entry will remain associated with the target object.
+ Associating an arbitrarily high number of listeners without explictitly
+ removing them will cause memory to grow unbounded even if ``once=True``
+ is specified.
+
.. note::
The :func:`.listen` function cannot be called at the same time
@@ -124,6 +131,13 @@ def listens_for(target, identifier, *args, **kw):
.. versionadded:: 0.9.4 Added ``once=True`` to :func:`.event.listen`
and :func:`.event.listens_for`.
+ .. warning:: The ``once`` argument does not imply automatic de-registration
+ of the listener function after it has been invoked a first time; a
+ listener entry will remain associated with the target object.
+ Associating an arbitrarily high number of listeners without explictitly
+ removing them will cause memory to grow unbounded even if ``once=True``
+ is specified.
+
.. seealso::
:func:`.listen` - general description of event listening
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index d923a6aa1..0e0e3f4df 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -1459,6 +1459,9 @@ def only_once(fn):
once = [fn]
def go(*arg, **kw):
+ # strong reference fn so that it isn't garbage collected,
+ # which interferes with the event system's expectations
+ strong_fn = fn # noqa
if once:
once_fn = once.pop()
return once_fn(*arg, **kw)