JerryCoder commited on
Commit
1211132
·
verified ·
1 Parent(s): 009e068

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +13 -2
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
- import asyncio
190
- asyncio.run(main())
 
 
 
 
 
 
 
 
 
 
 
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())