You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This lib should be run in async context, and it's recommended to use asyncio
However, the library depends on requests, a very good HTTP library that is blocking, which means that calls to boorus will also block, which is not aligned with the asyncio model.
Because of that, the following piece of code, inspired by the README:
importasyncioimportbooruasyncdefmain():
gel=booru.Gelbooru()
# search for 1000 random cat_girls, in parallel batches of 100 at once to the Gelbooru APIresults=awaitasyncio.gather(*[
gel.search("cat_girl sort:random")
for_inrange(10)
])
results= [booru.resolve(res) forresinresults]
print(results)
asyncio.run(main())
Will run each booru search sequentially, because requests.get blocks every other coroutine from doing any work. So, if gelbooru takes 1 second per request, that script would take a total of 10 seconds, where it would be expected for it to take around 1-3 seconds depending on network conditions and whatnot.
On my use-case, I create hundreds of tasks that are forced to operate sequentially, even though I want to have say, 10 of them running in parallel.
The library should either
Consider an async HTTP library for its internals, like aiohttp, or
Don't recommend itself as being used in an async context, as that is misleading.
The text was updated successfully, but these errors were encountered:
At the moment, the documentation of
booru
saysHowever, the library depends on
requests
, a very good HTTP library that is blocking, which means that calls to boorus will also block, which is not aligned with the asyncio model.Because of that, the following piece of code, inspired by the README:
Will run each booru search sequentially, because
requests.get
blocks every other coroutine from doing any work. So, if gelbooru takes 1 second per request, that script would take a total of 10 seconds, where it would be expected for it to take around 1-3 seconds depending on network conditions and whatnot.On my use-case, I create hundreds of tasks that are forced to operate sequentially, even though I want to have say, 10 of them running in parallel.
The library should either
The text was updated successfully, but these errors were encountered: