Update ccc.py
Browse files
ccc.py
CHANGED
@@ -7,11 +7,21 @@ import os
|
|
7 |
import logging
|
8 |
from fastapi import FastAPI
|
9 |
import uvicorn
|
|
|
10 |
|
11 |
# Disable all logging except for critical errors
|
12 |
logging.basicConfig(level=logging.CRITICAL)
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
@app.get("/")
|
17 |
async def root():
|
@@ -150,7 +160,6 @@ async def print_status_periodically():
|
|
150 |
await asyncio.sleep(60)
|
151 |
|
152 |
async def start_scanner():
|
153 |
-
initialize_base_ids()
|
154 |
tasks = []
|
155 |
instances_per_digit = 20000
|
156 |
|
@@ -161,9 +170,5 @@ async def start_scanner():
|
|
161 |
tasks.append(print_status_periodically())
|
162 |
await asyncio.gather(*tasks)
|
163 |
|
164 |
-
@app.on_event("startup")
|
165 |
-
async def startup_event():
|
166 |
-
asyncio.create_task(start_scanner())
|
167 |
-
|
168 |
if __name__ == "__main__":
|
169 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
7 |
import logging
|
8 |
from fastapi import FastAPI
|
9 |
import uvicorn
|
10 |
+
from contextlib import asynccontextmanager
|
11 |
|
12 |
# Disable all logging except for critical errors
|
13 |
logging.basicConfig(level=logging.CRITICAL)
|
14 |
|
15 |
+
@asynccontextmanager
|
16 |
+
async def lifespan(app: FastAPI):
|
17 |
+
# Startup
|
18 |
+
initialize_base_ids()
|
19 |
+
asyncio.create_task(start_scanner())
|
20 |
+
yield
|
21 |
+
# Shutdown
|
22 |
+
# Add any cleanup code here if needed
|
23 |
+
|
24 |
+
app = FastAPI(lifespan=lifespan)
|
25 |
|
26 |
@app.get("/")
|
27 |
async def root():
|
|
|
160 |
await asyncio.sleep(60)
|
161 |
|
162 |
async def start_scanner():
|
|
|
163 |
tasks = []
|
164 |
instances_per_digit = 20000
|
165 |
|
|
|
170 |
tasks.append(print_status_periodically())
|
171 |
await asyncio.gather(*tasks)
|
172 |
|
|
|
|
|
|
|
|
|
173 |
if __name__ == "__main__":
|
174 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|