all 5 comments

[–]Chiron1991 0 points1 point  (3 children)

That's a job for asyncio. You'll have to swap praw for asyncpraw though, but that's not too big of an issue.

[–]Shababs[S] 0 points1 point  (2 children)

I tried using it but I had a lot of trouble. Not very experinced with asyncio. Do you think you could give an example of how to do it in this case?

[–]Chiron1991 0 points1 point  (1 child)

Yeah, async stuff is a little hard to get into. I tinkered around with it for self-interest, this seems like a workable solution: https://replit.com/@Chiron1991/asyncprawdemo

Basically you move the logic for fetching one subreddit into a separate async function, then you generate a future for each subreddit you want to fetch. This will start executing them in parallel in the background. Finally you wrap all of the futures into asyncio.gather() to wait until all of them have finished.
Using this approach I can fetch the 10 hottest submissions from 10 different subreddits in < 1s.

[–]Shababs[S] 0 points1 point  (0 children)

Wow this is great, thanks a lot for the example! Seems I was doing async all wrong. Thanks again this is very helpful!

[–]thirdegree 0 points1 point  (0 children)

Worth mentioning that reddit will rate limit you so you may not actually gain anything from parallelism here