簡體   English   中英

在“ app” gunicorn中找不到應用程序對象“ app”

[英]Failed to find application object 'app' in 'app' gunicorn

我正在將燒瓶微服務與gunicorn一起使用,以請求托管在Google Kubernetes引擎上的服務。 微服務已通過dockerized托管,並且也作為Pod托管在Google kubernetes引擎上。 在本地對其進行測試之后,我對其進行了部署,但遇到了CrashLoopBackOff錯誤。 我的吊艙的日志是:

[2019-03-15 08:41:13 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2019-03-15 08:41:13 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2019-03-15 08:41:13 +0000] [1] [INFO] Using worker: threads
[2019-03-15 08:41:13 +0000] [12] [INFO] Booting worker with pid: 12
Failed to find application object 'app' in 'app'
[2019-03-15 08:41:13 +0000] [12] [INFO] Worker exiting (pid: 12)
[2019-03-15 08:41:13 +0000] [13] [INFO] Booting worker with pid: 13
Failed to find application object 'app' in 'app'
[2019-03-15 08:41:13 +0000] [13] [INFO] Worker exiting (pid: 13)
[2019-03-15 08:41:13 +0000] [1] [INFO] Shutting down: Master
[2019-03-15 08:41:13 +0000] [1] [INFO] Reason: App failed to load.

這對於gunicorn似乎是錯誤的。

我的文件夾結構是:

.
├── app.py
├── app.yaml
├── config.py
├── data
│   └── object_detection.pbtxt
├── Dockerfile
├── filename.jpg
├── helper.py
├── object_2.py
├── object_detection
│   ├── core
│   │   ├── anchor_generator.py

│       └── vrd_evaluation_test.py
├── object_detection_grpc_client.py

├── requirements.txt
└── tensorflow_serving
    ├── apis

       └── regression_pb2.py

app.py代碼為:

import logging

from flask import Flask, request, jsonify
from config import auth_secret_token, PORT, DEBUG_MODE
from helper import check_parameters
from object_detection_grpc_client import main


app = Flask(__name__)


def check_authorization(request):
    try:
        if not 'Auth-token' in request.headers:
            return jsonify({'error': 'unauthorized access'}), 401
        token = request.headers['Auth-token']
        if token != auth_secret_token:
            return jsonify({'error': 'unauthorized access'}), 401
        return "ok", 200
    except Exception as e:
        return jsonify({'error': 'unauthorized access'}), 401


@app.route("/", methods=['POST'])
def hello():
    info, status_code = check_authorization(request)

    if status_code != 200:
        return info, status_code
    else: 
        status, status_code = check_parameters(request.form)

    if status_code != 200:
        return status, status_code
    else:
        score = main()
        response = {"status": "success", "score": score, "customer_id":(request.form["cust_id"])}

        return jsonify(response), status_code


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=PORT, debug=DEBUG_MODE)

config.py代碼為:

    from os import environ as env
    import multiprocessing

    PORT = int(env.get("PORT", 8080))
    DEBUG_MODE = int(env.get("DEBUG_MODE", 1))

    # Gunicorn config
    bind = ":" + str(PORT)
    workers = multiprocessing.cpu_count() * 2 + 1
    threads = 2 * multiprocessing.cpu_count()

    auth_secret_token = "token"
    server='A.B.C.D:9000'
    model_name="mymodel"
    input_image='filename.jpg'
    label_map="./data/object_detection.pbtxt"

Dockerfile是:

    FROM python:3.5.2
    RUN apt update
    WORKDIR /app
    ADD requirements.txt /app/requirements.txt
    RUN pip install -r /app/requirements.txt
    ADD . /app
    ENV PORT 8080
    CMD ["gunicorn", "app:app", "--config=config.py"]

部署文件app.yaml:

 apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: mymodel-client
      labels:
        name: mymodel-client
    spec:
      replicas: 1
      selector:
        matchLabels:
          name: mymodel-client
      template:
        metadata:
          name: mymodel-client
          labels:
            name: mymodel-client
        spec:
          containers:
            - name: mymodel-client
              image: gcr.io/image-identification/mymodel-client:v1
              ports:
                - containerPort: 8080
              resources:
                requests:
                  memory: 256Mi
                limits:
                  memory: 512Mi
              env:
                - name: DEBUG_MODE
                  value: "1"

怎么了

鏈接到我提到的教程https://medium.com/google-cloud/a-guide-to-deploy-flask-app-on-google-kubernetes-engine-bfbbee5c6fb

我認為問題可能與此類似。 https://stackoverflow.com/a/50157417/4229159

app文件夾(您在docker中創建的文件夾)和app文件具有相同的名稱。 您可以重命名其中之一嗎?

其余文件看起來還不錯,這似乎只是gunicorn的問題

這很可能是內存問題。 我刪除了部署,並通過為其分配了更多資源將其再次推送,它開始運行,沒有任何錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM