python - uwsgi + flask + python print 在 request.get() 后停止工作
问题描述
尝试从控制台使用 uwsgi 记录 python 打印时遇到问题。
所以我从控制台运行我的应用程序:
uwsgi --http :9090 --wsgi-file wsgi.py --master -p 4
我的 wsgy.py 文件包含:
from assets_generator import app as application
if __name__ == "__main__":
app.run()
我的应用程序看起来像这样(在asset_generator.py 中):
from flask import Flask, render_template
app = Flask(__name__)
app.config.from_envvar('CONFIG')
from uwsgidecorators import thread
from worker import Worker
@thread
def _start_worker(item):
worker = Worker(item=item)
worker.run()
@app.route("/post-asset", methods=['GET', 'POST'])
def post_asset():
from flask import request
_start_worker(request.values)
return "OK", 200
worker 的 run 类调用了一个 convert 方法:
class Worker(object):
def __init__(self, item):
super(Worker, self).__init__()
self.item = item
def run(self):
with app.app_context():
# prepare stuff for convertion, fill urls etc....
details = self.convert(
name=self.item.get('name'),
source_url=self.item.get('source_url'),
conversion_format=self.item.get('format'),
default_options=default_options
)
并且转换方法调用一个url:
def convert(self, name, source_url, conversion_format, default_options):
try:
print "before requests " + source_url # THIS PRINT WORKS
r = requests.get(source_url)
print "after requests" # THIS ONE DOESN'T
# do other stuff, prints doesn't work
except Exception as e:
print " Error"
raise e
finally:
print "finally" # DOESN'T PRINT
if zip_extract_path:
shutil.rmtree(zip_extract_path)
print "before returning None" # DOESN'T PRINT
return None
我的问题是我可以在 uwsgi 控制台日志中看到第一个打印,但第二个实际上从未发生过,并且在此请求调用之后的任何其他打印都不会发生。
我已经手动测试过
r = requests.get(source_url)
使用来自运行此 uwsgi 应用程序的位置的正确 url,请求实际上成功并返回 OK。
我有点困惑为什么我的打印停止工作,如果有人对此有见解,将不胜感激。
解决方案
出于某种原因,在尝试打印一个不存在的变量并--py-autoreload 1
在 uwsgi 配置中进行设置后,现在显示了我的日志,但我不明白为什么。
推荐阅读
- python - 将鼠标悬停在 PyQt 中的链接上时更改文本颜色
- postgresql - 身份验证:PostgresSql 13.1 不考虑密码传递的部分连接字符串参数
- sql - PhpStorm SQL 编辑器:将 CURRENT_TIMESTAMP 或 now() 插入日期列
- javascript - 带有 minimax 的井字游戏机器人无法找到最佳动作
- java - Java setMaximizedbounds 在双屏环境下无法正常工作
- python - 在熊猫数据框中添加缺少的时间戳
- express - 在 Sequelize 中分组和计数
- java - 如何让这个while循环一次只提示用户一次
- python - discord.py 如何把它变成一个多赢的 gway 命令?
- mysql - 日期时间序列的 SQL 视图