gpt4 book ai didi

Python 程序在 "Debugger is Active"后挂起

转载 作者:行者123 更新时间:2023-12-05 06:40:03 25 4
gpt4 key购买 nike

我正在从以下 Github 存储库运行 app.py:https://github.com/fu-malaria/fu-malaria。该文件可以在 flask 文件夹中找到。当我运行它时,程序会打印以下内容并挂起。

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
libdc1394 error: Failed to initialize libdc1394
* Debugger is active!
* Debugger PIN: 347-063-980

我有 x11Forwarding。 libdc1394 错误 可以忽略。但是,我完全无法调试程序挂起的原因。有任何想法吗?我也粘贴了 app.py

   import os
from os import listdir
from os.path import isfile, join
from flask import Flask, request, redirect, url_for, render_template, flash, send_from_directory
from werkzeug.utils import secure_filename
import detector

UPLOAD_FOLDER = 'static/uploads/'
PROCESS_FOLDER = 'static/processed/'

GALLERY_RAW_FOLDER = 'static/gallery/'
GALLERY_PROC_FOLDER = 'static/gallery/'

THICK_GALLERY = 'imgThickBlood'
THIN_GALLERY = 'imgThinBlood'

STATS_EXTENSION = '.stats'

ALLOWED_EXTENSIONS = set(['jpg','jpeg','png','gif','bmp', 'tif','webp'])
process_cmd = 'python detect/basic_detector.py '


app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['PROCESS_FOLDER'] = PROCESS_FOLDER
app.config['GALLERY_RAW_FOLDER'] = GALLERY_RAW_FOLDER
app.config['GALLERY_PROC_FOLDER'] = GALLERY_PROC_FOLDER
app.config['THICK_GALLERY'] = THICK_GALLERY
app.config['THIN_GALLERY'] = THIN_GALLERY
app.config['STATS_EXTENSION'] = STATS_EXTENSION
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.secret_key = 'my secret malaria key'
tolerance = 50

# Index page handler
@app.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
inpath = app.config['UPLOAD_FOLDER']
outpath = app.config['PROCESS_FOLDER']
infile = os.path.join(app.config['UPLOAD_FOLDER'], filename)
outfile = os.path.join(app.config['PROCESS_FOLDER'], filename)
file.save(infile)
process_file(infile, outfile, str(tolerance))
return redirect(url_for('view_processed', inpath=inpath, outpath=outpath, filename=filename))
else:
# Show thin sample gallery for user to view as an example
gallery_path = app.config['GALLERY_PROC_FOLDER'] + app.config['THIN_GALLERY'] + 'Input/'
files = get_files(gallery_path)
return render_template('index.html', gallery_files=files, upload_path=gallery_path)


# Show processed file (redirect from index page file upload form)
@app.route('/view_processed/<filename>')
def view_processed(filename):
inpath = app.config['UPLOAD_FOLDER']
outpath = app.config['PROCESS_FOLDER']
red, malaria = get_stats(outpath, filename)
return render_template('process.html', input_file=inpath, output_file=outpath, filename=filename, red=red, malaria=malaria)


# Show processed file (redirect from index page gallery)
@app.route('/mini_gallery/<filename>')
def mini_gallery(filename):
inpath = app.config['GALLERY_RAW_FOLDER'] + app.config['THIN_GALLERY'] + 'Input/'
outpath = app.config['GALLERY_PROC_FOLDER'] + app.config['THIN_GALLERY'] + 'Output/'
red, malaria = get_stats(outpath, filename)
return render_template('process.html', input_file=inpath, output_file=outpath, filename=filename, red=red, malaria=malaria)

# Gallery handler
@app.route('/gallery', methods=['GET','POST'])
def gallery():
if request.method == 'POST':
threshold = request.form.get('thresholdRadio')
gallery = request.form.get('galleryRadio')

if int(threshold) < 0 or int(threshold) > 100:
return render_template('gallery.html')

if not 'thin' in gallery and not 'thick' in gallery:
return render_template('gallery.html')

if 'thin' in gallery:
inpath = app.config['GALLERY_RAW_FOLDER'] + app.config['THIN_GALLERY'] + 'Input/'
outpath = app.config['GALLERY_PROC_FOLDER'] + app.config['THIN_GALLERY'] + 'Output/'
else:
inpath = app.config['GALLERY_RAW_FOLDER'] + app.config['THICK_GALLERY'] + 'Input/'
outpath = app.config['GALLERY_PROC_FOLDER'] + app.config['THICK_GALLERY'] + 'Output/'

files = get_files(inpath)

for f in files:
process_file(inpath+'/'+f, outpath+'/'+f, str(threshold))

return render_template('gallery.html', gallery_list=files, gallery_inpath=inpath, gallery_outpath=outpath)

else:
inpath = app.config['GALLERY_RAW_FOLDER'] + app.config['THIN_GALLERY'] + 'Input/'
outpath = app.config['GALLERY_PROC_FOLDER'] + app.config['THIN_GALLERY'] + 'Output/'
files = get_files(inpath)
return render_template('gallery.html', gallery_list=files, gallery_inpath=inpath, gallery_outpath=outpath)


# Gets list of image files excluding .stats files
def get_files(gallery_path):
files = [f for f in listdir(gallery_path) if isfile(join(gallery_path, f))]
files = [f for f in files if allowed_file(f)]
return files


# Do malaria detection image processing
def process_file(inpath, outpath, threshold):
detector.process(inpath, outpath, str(threshold))


# Simple validation of files allowed for upload based on file extension
def allowed_file(filename):
return '.' in filename and filename.rsplit('.',1)[1] in ALLOWED_EXTENSIONS

# Get stats about processed image from file
# Saving stats to file as database not really necessary, and avoiding re-processing to get stats
def get_stats(outpath, filename):
statsfile = outpath+'/'+filename+app.config['STATS_EXTENSION']
red = 0
malaria = 0
with open(statsfile, mode='r') as f:
red = f.readline()
malaria = f.readline()
return red, malaria


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

最佳答案

您使用命令行启动应用程序,但您是否随后打开了一个 Web 浏览器到端口 5000 上的该机器?

听起来您正在远程连接到该计算机,因此您需要修改 app.run() 参数:

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

当您再次运行 app.py 文件时,您应该会在打印语句中看到地址更改:

python app.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 142-103-744

此时只需将 Web 浏览器指向在端口 5000 上运行 Flask WSGI 应用程序的机器

在 192.168.1.15 运行 WSGI 应用程序的远程计算机的示例 URL:

http://192.168.1.15:5000

关于Python 程序在 "Debugger is Active"后挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43673549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com