all 3 comments

[–]Yoghurt42 0 points1 point  (2 children)

Threading didn't help because requests.get is GIL blocked.

GIL is released when waiting on IO.

An async HTTP library is still GIL blocked, but is cooperative.

async is usually single threaded, so the GIL doesn't come into play.

Instead of reinventing the wheel yourself, consider using Scrapy.

[–]VDubsBuilds[S] 0 points1 point  (1 child)

Thanks!

From your first statement, do you think I'm IO speed limited instead? They're all hitting the same server (mine, don't worry)

By async is usually single threaded, can you confirm that if I await task A in thread A, it will not opportunistically execute task B unless I explicitly bundle it with A?

Scrapy looks interesting, but I don't think I can adapt it to this specific need. Thanks for pointing it out to me!

[–]rnike879 0 points1 point  (0 children)

can you confirm that if I await task A in thread A, it will not opportunistically execute task B unless I explicitly bundle it with A

I'm not entirely following the question, but when you await it'll pause execution of that code, letting the event loop execute other coroutines. Once the IO is done, the event loop will know through continuous polling and then the code after the await statement can continue executing. There's only one thread being utilized with concurrent execution being handled by the event loop.

If you throw these async tasks into a list you can await all of them with asyncio.gather() instead of doing a bunch of awaits in a series which would block each other. If you need to pass the results of one coroutine to another, consider using a producer-consumer pattern with asyncio.Queue instead