Does fastapi and asyncio both run at the same time in this code : "# main.py from…
Jump to turn (7)
- 1Does fastapi and asyncio both run at the same time in this code : "# main.py fro
- 2Ok then give me fully complete and correct code
- 3okay now how to call the app and how will it work? what is it's purpose?
- 4How many tasks can I schedule through this app on a single core vps with 512MB r
- 5it is plain function nothing complex and the payload size is only 1 KB. Give me
- 6explain this code : "import requests def sendvanishingmessage(token, chatid, tex
- 7yeah you're right that is where I want to use that asyncio app which I provided
- User
Does fastapi and asyncio both run at the same time in this code : "# main.py from fastapi import FastAPI import asyncio import aiohttp import json from motor.motor_asyncio import AsyncIOMotorClient import aioredis
app = FastAPI()
MongoDB connection
MONGO_URI = "mongodb://localhost:27017" mongo_client = AsyncIOMotorClient(MONGO_URI) db = mongo_client["payloads_db"] payloads_collection = db["payloads"]
Redis connection
REDIS_URL = "redis://localhost" redis = None
async def get_redis(): global redis if redis is None: redis = await aioredis.create_redis_pool(REDIS_URL) return redis
async def send_payload_with_delay(payload, delay, endpoint): await asyncio.sleep(delay) async with aiohttp.ClientSession() as session: async with session.post(endpoint, data=json.dumps(payload)) as response: print(f"Payload sent: {payload}, Response: {response.status}")