Flask Socket IO服务器未检测到更改

问题描述 投票:1回答:1

即使启用了调试模式,在保存文件后,服​​务器似乎也未检测到对application.py文件所做的更改。我能够看到更改的唯一方法是退出服务器并使用flask run重新启动

这是application.py的代码:

import os
import requests

from flask import Flask, session, render_template, request, url_for, flash, redirect, jsonify
from flask_socketio import SocketIO, emit

app = Flask(__name__)
app.config["SECRET_KEY"] = 'secret!'
socketio = SocketIO(app)

@app.route("/")
def index():
    print('hello world')
    return 'hello!'

if __name__ == '__main__':
    socketio.run(app, debug=True)

这是命令行/终端:

λ flask run
 * Serving Flask-SocketIO app "application.py"
 * Forcing debug mode on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 156-884-244
(3824) wsgi starting up on http://127.0.0.1:5000
(3824) accepted ('127.0.0.1', 50569)
127.0.0.1 - - [10/Sep/2018 20:07:40] "GET /socket.io/?EIO=3&transport=polling&t=1536624459432-5 HTTP/1.1" 200 381 0.000000
(3824) accepted ('127.0.0.1', 50571)
127.0.0.1 - - [10/Sep/2018 20:07:40] "GET /socket.io/?EIO=3&transport=polling&t=1536624460314-6&sid=79eb8e587f664e3383c946bb046717ca HTTP/1.1" 200 215 0.000000
(3824) accepted ('127.0.0.1', 50568)
127.0.0.1 - - [10/Sep/2018 20:07:44] "GET /socket.io/?EIO=3&transport=websocket&sid=79eb8e587f664e3383c946bb046717ca HTTP/1.1" 200 0 4.610168
hello world
127.0.0.1 - - [10/Sep/2018 20:07:44] "GET / HTTP/1.1" 200 152 0.000000
hello world
127.0.0.1 - - [10/Sep/2018 20:07:58] "GET / HTTP/1.1" 200 152 0.000000
hello world
127.0.0.1 - - [10/Sep/2018 20:08:06] "GET / HTTP/1.1" 200 152 0.000000
wsgi exiting
(3824) wsgi exited, is_accepting=True

每当我更改hello world中的文本并刷新浏览器时,这些print('hello world')的命令就会显示出来。无论我将其更改为什么,我总是得到代码的print参数的原始版本。

我注意到几件事情:

  • 当我刚刚运行Flask时,不会发生此问题。当我刚刚运行Flask时,我在命令行/终端中看到检测到更改。
  • 如果我返回HTML文件的模板,则会自动更新对HTML文件的更改。
python flask flask-socketio
1个回答
1
投票

嗯。看起来重新加载器不适用于您通过flask run运行应用程序。但是,当您通过运行应用程序文件(即python application.py)运行它时,它确实有效。

我会记录一个错误并进行调查。

© www.soinside.com 2019 - 2024. All rights reserved.