hal*_*ang 0 python flask blinker
我想知道我是否可以使用闪烁库(或者可能使用任何库)来完成这些工作。
app.py),我定义了一个名为updated(例如blinker.signal('updated'))的信号。subscriber)连接(订阅)到更新后的信号。这个过程就像守护进程一样永远运行。subscriber调用该函数。所以我写了一些代码:
app.py(烧瓶应用程序)
from flask import Flask
from blinker import signal
app = Flask(__name__)
updated = signal('updated')
@app.route('/update')
def update():
updated.send('nothing')
return 'Updated!'
Run Code Online (Sandbox Code Playgroud)
背景.py
import time
from app import updated
@updated.connect
def subscriber(*args, **kwargs):
print('An update occurred on the web side!')
while True:
print('Waiting for signals...')
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
并使用flask run命令运行 Web 应用程序。现在,当我访问时localhost:5000/update,我可以Updated!在浏览器中看到消息,但看不到An update occurred on the web side!来自其他进程的消息。
我的方法错了吗?如果是,我怎么能做这样的工作?等待您的答复,谢谢。