Skip to content

Added asycn requests

Raj Singh Gogia requested to merge added-async-req into main

Created by: waraich1

  • Earlier, we were making sync requests like this
subreddit = self.reddit.subreddit(subredditName)
for submission in
	post_comment = comment.get_comment(, "hot", False, self.token)
return res
  • This was causing API to take almost 10 seconds
  • To fix this I used HTTPX library which basically make concurrent requests like this
async  def  do_tasks():
     async  with  httpx.AsyncClient() as  client:
         tasks = [client.get(url, headers=headers, follow_redirects=True) for  url  in  res]
         result = await  asyncio.gather(*tasks)
         return  result
res =

This makes all the get requests concurrently which imroves the time

Merge request reports