Compresas-2 / app.py
saske560's picture
Update app.py
41d5811 verified
Raw History Blame Contribute Delete
511 Bytes
from fastapi import FastAPI
from contextlib import asynccontextmanager
import threading
import os
def run_bot():
print('Bot lanzado desde FastAPI')
os.system('python main.py')
@asynccontextmanager
async def lifespan(app: FastAPI):
bot_thread = threading.Thread(target=run_bot)
bot_thread.start()
yield # Aquí FastAPI inicia
# Aquí podrías hacer limpieza al apagar si quisieras
app = FastAPI(lifespan=lifespan)
@app.get("/")
def read_root():
return {"message": "Bot online"}