我有一个功能 index ,该功能会拍摄一张图像并将其传递给处理功能 run ,该功能是从另一个模块( true.detect.py )。
当我尝试在 index 函数中完成任务job = q.enqueue(run, img
)时,出现导入错误
12:02:13 default: true.detect.run('/home/y700/projects/ultratrue/app/uploads/honey-bee-2-1qf37bs.jpg') (7544ed7c-7274-416c-bc83-daa90d7fe0c1)
12:02:13 ModuleNotFoundError: No module named 'true'
文件夹结构
project
-true
--detect.py
--other files
-app
--app.py
--main.py
app.py
basedir = os.path.abspath(os.path.join(os.path.dirname( __file__ )))
UPLOAD_FOLDER = basedir + '/uploads'
ALLOWED_EXTENSIONS = set(["jpg"])
app = Flask(__name__)
app.config.from_object(Configuration)
base = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..'))
sys.path.append(base)
from true.detect import run
#Connect to redis DB
from redis import Redis
from rq import Queue
q = Queue(connection=Redis())
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
...load and save img file logic....
........
img = (os.path.join(app.config['UPLOAD_FOLDER'], filename))
job = q.enqueue(run, img)
if job.is_finished:
return redirect(url_for("result", count=count))
else:
return "Wait"
return render_template("index.html")
但是,然后我改变了
job = q.enqueue(run, img)
if job.is_finished:
return redirect(url_for("result", count=count))
else:
return "Wait"
不使用任务队列即可进行标准功能调用
count = run(img)
return redirect(url_for("result", count=count))
一切开始。