-
-
Save nyimbi/0e0063e34a172e15b2c6cb86ed29debf 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