Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -728,6 +728,13 @@ def background_scraper_loop():
|
|
| 728 |
|
| 729 |
@asynccontextmanager
|
| 730 |
async def lifespan(app: FastAPI):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
# Startup
|
| 732 |
threading.Thread(target=background_scraper_loop, daemon=True).start()
|
| 733 |
yield
|
|
@@ -1026,8 +1033,9 @@ if __name__ == "__main__":
|
|
| 1026 |
elif args.run:
|
| 1027 |
# Launch FastAPI which internally starts the loop
|
| 1028 |
port = int(os.getenv("PORT", 7860))
|
| 1029 |
-
|
|
|
|
| 1030 |
else:
|
| 1031 |
# Default behavior: run FastAPI
|
| 1032 |
port = int(os.getenv("PORT", 7860))
|
| 1033 |
-
uvicorn.run(app, host="0.0.0.0", port=port
|
|
|
|
| 728 |
|
| 729 |
@asynccontextmanager
|
| 730 |
async def lifespan(app: FastAPI):
|
| 731 |
+
# Hijack Uvicorn's loggers recursively after they start up
|
| 732 |
+
logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
|
| 733 |
+
for log_name in ("uvicorn", "uvicorn.error", "uvicorn.access", "fastapi"):
|
| 734 |
+
l = logging.getLogger(log_name)
|
| 735 |
+
l.handlers = []
|
| 736 |
+
l.propagate = True
|
| 737 |
+
|
| 738 |
# Startup
|
| 739 |
threading.Thread(target=background_scraper_loop, daemon=True).start()
|
| 740 |
yield
|
|
|
|
| 1033 |
elif args.run:
|
| 1034 |
# Launch FastAPI which internally starts the loop
|
| 1035 |
port = int(os.getenv("PORT", 7860))
|
| 1036 |
+
# Remove log_config=None because it completely disables Uvicorn's stdout handling
|
| 1037 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 1038 |
else:
|
| 1039 |
# Default behavior: run FastAPI
|
| 1040 |
port = int(os.getenv("PORT", 7860))
|
| 1041 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|