Spaces:
Sleeping
Sleeping
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -2,6 +2,7 @@ import os, io, sys, zipfile, base64, random, shutil, subprocess, tempfile
|
|
| 2 |
from pathlib import Path
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from starlette.responses import JSONResponse
|
|
|
|
| 5 |
|
| 6 |
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
| 7 |
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
|
|
@@ -186,5 +187,15 @@ async def root():
|
|
| 186 |
return JSONResponse(content={"status": "success", "bot": "running"})
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from starlette.responses import JSONResponse
|
| 5 |
+
import asyncio
|
| 6 |
|
| 7 |
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
| 8 |
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
|
|
|
|
| 187 |
return JSONResponse(content={"status": "success", "bot": "running"})
|
| 188 |
|
| 189 |
if __name__ == "__main__":
|
| 190 |
+
# Check if loop is already running (Hugging Face Spaces does this)
|
| 191 |
+
try:
|
| 192 |
+
loop = asyncio.get_running_loop()
|
| 193 |
+
except RuntimeError:
|
| 194 |
+
loop = None
|
| 195 |
+
|
| 196 |
+
if loop and loop.is_running():
|
| 197 |
+
# Already running loop: create task directly
|
| 198 |
+
asyncio.create_task(main())
|
| 199 |
+
else:
|
| 200 |
+
# Not running: run normally
|
| 201 |
+
asyncio.run(main())
|