Signals

List of used signals

This models contains all the signals used by the library.

save_to_db.core.signals.after_db_persist = <Signal('after_db_persist')>

Signal is emitted when a persistance process is completed.

Parameters:
  • items – List of persisted items.
  • models – List of lists of persisted models corresponding to the list of items. One item can have more then one model updated.
save_to_db.core.signals.before_db_persist = <Signal('before_db_persist')>

Signal is emitted when a persistance process is started.

Parameters:
  • item – The item that was used to persist the data.
  • item_structure – Dictionary with single item classes as keys and lists of single item instances as values.
save_to_db.core.signals.item_dropped = <Signal('item_dropped')>

Signal is emitted during persistence process for an item cannot that be used for persistence.

Note

If possible, related items will still be persisted.

Parameters:
  • item – A dropped item.
  • reason (str) – A short explanation why the item was dropped.

Signal class

class save_to_db.core.utils.signal.Signal(name)[source]

Bases: object

This class is used to emit signals.

Variables:name – Signal name.
clear()[source]

Removes all listeners from the signal.

emit(*args, **kwargs)[source]

Emits the signal. All listeners will be called with the same arguments as this method.

register(listener)[source]

Registers listener to the signal.

Note

This method can be also used as a decorator:

signal = Signal('MySignal')

@signal.register
def signal_listener(value):
    print('Signal value: {}'.format(value))

# Output: "Signal value: Demo Value"
signal.emit('Demo Value')
unregister(listener)[source]

Unregisters listener from the signal.