summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/event
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-08-02 23:20:06 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-08-04 12:40:11 -0400
commite22d2b089fad1f79d53bc6238626f32f0e796ad0 (patch)
tree46997483eceb659d61b4bc00033624a7aef4b999 /lib/sqlalchemy/event
parenta4e0995dc817acda7d669b8925c9bc3defdb660b (diff)
downloadsqlalchemy-e22d2b089fad1f79d53bc6238626f32f0e796ad0.tar.gz
Strong reference listen function wrapped by "once"
Fixed issue in event system where using the ``once=True`` flag with dynamically generated listener functions would cause event registration of future events to fail if those listener functions were garbage collected after they were used, due to an assumption that a listened function is strongly referenced. The "once" wrapped is now modified to strongly reference the inner function persistently, and documentation is updated that using "once" does not imply automatic de-registration of listener functions. Fixes: #4794 Change-Id: I06388083d1633dcc89e8919eb1e51270f966df38
Diffstat (limited to 'lib/sqlalchemy/event')
-rw-r--r--lib/sqlalchemy/event/api.py14
1 files changed, 14 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