gpt4 book ai didi

python - 使用任何 Firestore 功能时 Gunicorn Worker 超时 - 甚至不是 get

转载 作者:行者123 更新时间:2023-12-04 13:40:35 25 4
gpt4 key购买 nike

我在 native 模式下处理 Cloud Firestore 时遇到了很多麻烦。我习惯使用 NDB,但尝试将我的应用程序更改为灵活环境,因为我需要使用 websocket。但是,我真的有一个使用 Firestore 的噩梦。我不得不使用 Tasks API 来做一个简单的批量提交,效果很好。但是我无法从数据库中检索单个文档,无论是本地还是部署。在本地,我不断收到:

[2019-08-31 20:05:17 -0300] [1951] [INFO] Booting worker with pid: 1951
[2019-08-31 20:05:47 -0300] [1927] [CRITICAL] WORKER TIMEOUT (pid:1951)
[2019-08-31 20:05:48 -0300] [1964] [INFO] Booting worker with pid: 1964
[2019-08-31 20:06:18 -0300] [1927] [CRITICAL] WORKER TIMEOUT (pid:1964)
[2019-08-31 20:06:19 -0300] [1977] [INFO] Booting worker with pid: 1977

我有一个名为 Contacts 的集合,其中包含一个名为 5599999999 的文档,其中包含一对值:“name”:“test”。另外,我在本地使用 gunicorn 运行,因为我需要 websockets。

这是在本地运行的命令:
gunicorn -b 127.0.0.1:8080 -k flask_sockets.worker  main:app --reload

还有我的 app.yaml 文件:
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT -k flask_sockets.worker main:app

runtime_config:
python_version: 3

manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10

主文件
import googleapiclient.discovery
import asyncio
import google.cloud.exceptions
import firebase_admin
from google.cloud import firestore
from google.oauth2 import service_account
from firebase_admin import credentials, firestore
from flask import Flask, render_template
from flask_sockets import Sockets

cred = credentials.Certificate('service.json')
firebase_admin.initialize_app(cred)
app = Flask(__name__)
sockets = Sockets(app)

@app.route('/')
def index():

teste = GetContacts()

return str(teste.to_dict())

def GetContacts():
db = firestore.client()
contacts = db.collection(u'Contacts').document(u'5599999999').get()
return contacts


我只是希望它的输出是一对值。但它会无限期地运行......

现在试过了,只有 Flask。运行流畅。完全没有问题,而且速度很快。但是,除了获得一对值之外,我也遇到了这种错误:
$ python main.py
* 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:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 325-288-398
127.0.0.1 - - [01/Sep/2019 01:03:53] "GET / HTTP/1.1" 200 -
ERROR:root:An error occurred during a request.
Traceback (most recent call last):
File "/Users/dr/env/lib/python3.7/site-packages/flask_sockets.py", line 40, in __call__
handler, values = adapter.match()
File "/Users/dr/env/lib/python3.7/site-packages/werkzeug/routing.py", line 1799, in match
raise NotFound()
werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/dr/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/dr/env/lib/python3.7/site-packages/flask/app.py", line 1791, in dispatch_request
self.raise_routing_exception(req)
File "/Users/dr/env/lib/python3.7/site-packages/flask/app.py", line 1774, in raise_routing_exception
raise request.routing_exception
File "/Users/dr/env/lib/python3.7/site-packages/flask/ctx.py", line 336, in match_request
self.url_adapter.match(return_rule=True)
File "/Users/dr/env/lib/python3.7/site-packages/werkzeug/routing.py", line 1799, in match
raise NotFound()
werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
127.0.0.1 - - [01/Sep/2019 01:03:53] "GET /favicon.ico HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [01/Sep/2019 01:03:53] "GET /favicon.ico HTTP/1.1" 200 -

最佳答案

这与gevent有关(由 flask_sockets 使用)和 grpc (由 firebase 使用)此问题中描述的冲突 https://github.com/grpc/grpc/issues/4629解决方法是添加以下代码

import grpc.experimental.gevent as grpc_gevent
grpc_gevent.init_gevent()

关于python - 使用任何 Firestore 功能时 Gunicorn Worker 超时 - 甚至不是 get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57742213/

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