为什么我要实例化两个不同的队列?
Why am I instantiating two different queues?
我正在尝试设置一个应用程序,它将使用 python 和 flask-restful 接收 HTTP GET 和 POST。我遇到的问题是,当我启动应用程序时,我看到生成了两个队列实例。我希望你能帮我理解为什么?
应用程序输出(终端):
<queue.Queue object at 0x10876fdd8>
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
<queue.Queue object at 0x10ce48be0>
* Debugger is active!
* Debugger PIN: 292-311-362
Python代码(运行用下面的命令python -m main
):
import json
from flask import Flask, request
from flask_restful import Resource, Api, reqparse
import requests
import os
import threading
import queue
import sys
app = Flask(__name__)
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("endpoint")
queue = queue.Queue()
base_path = os.path.dirname(os.path.realpath(__file__))
config = Json_Parser().get_json_object(base_path + "path")
consumer = Consumer(config, queue)
t1 = threading.Thread(target=consumer.consume)
t1.start()
class Interaction(Resource):
def get(self):
self.create_interaction()
thread_queue = consumer.get_queue()
output = thread_queue.get()
return output
api.add_resource(Interaction, '/interaction')
if __name__ == '__main__':
print(queue)
app.run(debug=True)
在@Richar de Wit 的帮助下,我更改了以下行:
app.run(debug=True)
至:
app.run(debug=True, use_reloader=False)
防止调试器实例化两个队列,从而在以后出现问题。
本题中引用的问题:
Why does running the Flask dev server run itself twice?
我正在尝试设置一个应用程序,它将使用 python 和 flask-restful 接收 HTTP GET 和 POST。我遇到的问题是,当我启动应用程序时,我看到生成了两个队列实例。我希望你能帮我理解为什么?
应用程序输出(终端):
<queue.Queue object at 0x10876fdd8>
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
<queue.Queue object at 0x10ce48be0>
* Debugger is active!
* Debugger PIN: 292-311-362
Python代码(运行用下面的命令python -m main
):
import json
from flask import Flask, request
from flask_restful import Resource, Api, reqparse
import requests
import os
import threading
import queue
import sys
app = Flask(__name__)
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("endpoint")
queue = queue.Queue()
base_path = os.path.dirname(os.path.realpath(__file__))
config = Json_Parser().get_json_object(base_path + "path")
consumer = Consumer(config, queue)
t1 = threading.Thread(target=consumer.consume)
t1.start()
class Interaction(Resource):
def get(self):
self.create_interaction()
thread_queue = consumer.get_queue()
output = thread_queue.get()
return output
api.add_resource(Interaction, '/interaction')
if __name__ == '__main__':
print(queue)
app.run(debug=True)
在@Richar de Wit 的帮助下,我更改了以下行:
app.run(debug=True)
至:
app.run(debug=True, use_reloader=False)
防止调试器实例化两个队列,从而在以后出现问题。
本题中引用的问题:
Why does running the Flask dev server run itself twice?