If you want to create and send signals in your own code (for example, if you are writing an extension), create a new Signal
instance and call send
when the subscribers should be notified. Signals are created using a Namespace
.
from flask import current_app
from flask.signals import Namespace
namespace = Namespace()
message_sent = namespace.signal('mail_sent')
def message_response(recipient, body):
...
message_sent.send(
current_app._get_current_object(),
recipient=recipient,
body=body
)
@message_sent.connect
def log_message(app, recipient, body):
...
Prefer using Flask's signal support over using Blinker directly. It wraps the library so that signals remain optional if developers using your extension have not opted to install Blinker.