我有一个(一些)交易机器人,它在Google上运行24/7,运行于Python中,通过restAPI控制,使用FASTApi进行控制。我的机器人都有自己的云运行实例。他们大部分时间都执行得很好.我可以拿到我想放在前端的数据。然而,有时我注意到WSGI应用程序在CLoudRun上重新启动?这样做就阻止了我的循环交易功能。因为大多数情况下这是没有问题的,我已经发生了中期交易,这是令人不安的。我会贴几个片段,希望能在答案中提供上下文。谢谢。
FROM python:3.10
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
CMD exec python3 -m uvicorn bot_handler:app --host 0.0.0.0 --port 8080
@app.get('/start',dependencies=[Depends(JWTBearer())])
def start():
thread=Thread(target=bot_instance.start)
thread.daemon=True
thread.start()
return {"status":200}
Info
2022-10-14 21:16:22.402 MSTGET200670 B3 mspython-requests/
Default
2022-10-14 21:42:26.421 MSTINFO: Shutting down
Default
2022-10-14 21:42:26.523 MSTINFO: Waiting for application shutdown.
Default
2022-10-14 21:42:26.523 MSTINFO: Application shutdown complete.
Default
2022-10-14 21:42:26.523 MSTINFO: Finished server process [1]
Default
2022-10-14 21:42:41.955 MSTINFO: Started server process [1]
Default
2022-10-14 21:42:41.955 MSTINFO: Waiting for application startup.
Default
2022-10-14 21:42:41.956 MSTINFO: Application startup complete.
Default
2022-10-14 21:42:41.956 MSTINFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
Default
2022-10-14 22:58:52.745 MSTVALIDATING CONFIG FILE...
发布于 2022-10-15 07:50:53
云运行实例是短暂的。云运行服务的目的是处理请求,而不是运行后台任务。如果实例没有主动处理请求,Cloud可能会关闭它,如果需要更新主机,则Cloud可以关闭它(如果设置了minScale或得到更多请求,则可以拆分新实例)。如果您需要一个不重新启动的实例,除非您告诉它,那么使用一个VM。
https://stackoverflow.com/questions/74077239
复制相似问题