diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-11 12:27:10 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-11 12:27:10 -0400 |
| commit | 009df6a3d041e517cc9efa74d3c87184357a5006 (patch) | |
| tree | 1f76d29b586de7052c1baaf286407d4245795788 /lib/sqlalchemy/event/api.py | |
| parent | 043dc4a2c1eef11abc04919d0cc093f5424028e5 (diff) | |
| download | sqlalchemy-009df6a3d041e517cc9efa74d3c87184357a5006.tar.gz | |
- Added a new keyword argument ``once=True`` to :func:`.event.listen`
and :func:`.event.listens_for`. This is a convenience feature which
will wrap the given listener such that it is only invoked once.
Diffstat (limited to 'lib/sqlalchemy/event/api.py')
| -rw-r--r-- | lib/sqlalchemy/event/api.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/sqlalchemy/event/api.py b/lib/sqlalchemy/event/api.py index 20e74d90e..b27ce7993 100644 --- a/lib/sqlalchemy/event/api.py +++ b/lib/sqlalchemy/event/api.py @@ -44,6 +44,18 @@ def listen(target, identifier, fn, *args, **kw): "after_parent_attach", unique_constraint_name) + + A given function can also be invoked for only the first invocation + of the event using the ``once`` argument:: + + def on_config(): + do_config() + + event.listen(Mapper, "before_configure", on_config, once=True) + + .. versionadded:: 0.9.3 Added ``once=True`` to :func:`.event.listen` + and :func:`.event.listens_for`. + """ _event_key(target, identifier, fn).listen(*args, **kw) @@ -63,6 +75,18 @@ def listens_for(target, identifier, *args, **kw): table.name, list(const.columns)[0].name ) + + A given function can also be invoked for only the first invocation + of the event using the ``once`` argument:: + + @event.listens_for(Mapper, "before_configure", once=True) + def on_config(): + do_config() + + + .. versionadded:: 0.9.3 Added ``once=True`` to :func:`.event.listen` + and :func:`.event.listens_for`. + """ def decorate(fn): listen(target, identifier, fn, *args, **kw) |
