File size: 511 Bytes
a69f31a
41d5811
 
 
7efc265
41d5811
 
 
7efc265
 
41d5811
 
 
 
 
7efc265
41d5811
7efc265
41d5811
 
 
7efc265
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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"}