-
-
Save johndiego/8e7563bdf9efa3f2e45e3d9dc3cc0ae4 to your computer and use it in GitHub Desktop.
Blinker/Signal Flask Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, current_app | |
from blinker import Namespace | |
app = Flask(__name__) | |
app.secret_key = 'WOO' | |
my_signals = Namespace() | |
def moo_signal(app, message, **extra): | |
print(message) | |
moo = my_signals.signal('moo') | |
moo.connect(moo_signal, app) | |
@app.route('/', methods=['POST', 'GET']) | |
def home(): | |
moo.send(current_app._get_current_object(), message='Hi') | |
moo.send(current_app._get_current_object(), message='Hi') | |
moo.send(current_app._get_current_object(), message='Hi') | |
return 'toot' | |
if __name__ == '__main__': | |
app.run(debug=True, port=5002) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment