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
I was deep into my project when I embarrassingly noticed that the pokeapi wrapper I used ( PokeBase by Greg Hilmes) is not asynchronous.
Now I have the issue that I am not particularly experienced in this field and the wrapper is already fairly deeply integrated into the project.
So does anybody already have some sort of asynchronous python wrapper or would be willing to create one?
Any help would be greatly appreciated as I don't think that I could create something efficient in a timely manner!
Yes, I do. I am using it for a discord bot which are async.
The issue is that it only works until it doesnt basically. Sometimes when the call took too long the bot could be cause to hang up and disconnect. It only happened rarely so I didn't know what caused it.
This is an unintended behaviour that causes some issues and the only way to resolve it would be asynchronous request via aiohttp for example instead of urllib and requests.
I'm not really a Python geek, but in Javascript we can wrap synchronous method in Promises (which are async) and thus transforming blocking to non-blocking, is it possible in Python?
Exactly. Asynchronous code doesnt really get along that well together with blocking code.
It's something also often referred to as "async creep".
On a really simple level I would only have to do my requests with aiohttp instead of urllib and requests but just changing this in the current pokebase wrapper doesnt work as asynchronus functions can only be called in other asynchronous functions. The async creep I mentioned before.
Hm, that actually sounds promissing for now. I will give it a go!
Still, a fully asynchronous wrapper might be neat at some point .-. Since this does look kinda wonky and always adds an extra step. But as long as it works 😅 💪
Sorry for neglecting the conversation for so long. I'm interested in an async wrapper, I just don't have the experience or the time to do that at the moment. That being said, I like the simplicity of having non-async calls, especially for new programmers using this to learn, along with PokeAPI. Perhaps pokebase-async could be another fork/repo which is a separate PyPI package, give the time to put that together. @AtomToast, I would do as @Naramsim suggested, and fork my repo and build the async wrapper, and of course, in the meantime, use this with your bot. Closing now.
Sry for posting on this closed issue but I've been looking for an async fork of this and I haven't found anything. So, since I'm quite experienced with the async framework and I've already done another async API wrapper (for Hypixel), I'd like to do that. I will start working on it as soon as I can and I'll post a message in this thread once it's done/usable.
Is that OK?
Reacted by Alessandro Pezzè, AtomToast and Kronopt
Activity
Naramsim commentedon Mar 2, 2018
Do you want to use the wrapper with asyncio?
https://docs.python.org/3/library/asyncio.html
Why the wrapper did work until now? Why doesn't fit anymore? What do you want to achieve with an async wrapper?
AtomToast commentedon Mar 2, 2018
Yes, I do. I am using it for a discord bot which are async.
The issue is that it only works until it doesnt basically. Sometimes when the call took too long the bot could be cause to hang up and disconnect. It only happened rarely so I didn't know what caused it.
This is an unintended behaviour that causes some issues and the only way to resolve it would be asynchronous request via aiohttp for example instead of urllib and requests.
Here is a short description from the discord.py docs: http://discordpy.readthedocs.io/en/latest/faq.html#what-does-blocking-mean
Naramsim commentedon Mar 2, 2018
So if I understand correctly the request this wrapper make are disturbing the asyncio event loop? So it results that the event loop sometimes fails?
Naramsim commentedon Mar 2, 2018
I'm not really a Python geek, but in Javascript we can wrap synchronous method in Promises (which are async) and thus transforming blocking to non-blocking, is it possible in Python?
AtomToast commentedon Mar 2, 2018
Exactly. Asynchronous code doesnt really get along that well together with blocking code.
It's something also often referred to as "async creep".
On a really simple level I would only have to do my requests with aiohttp instead of urllib and requests but just changing this in the current pokebase wrapper doesnt work as asynchronus functions can only be called in other asynchronous functions. The async creep I mentioned before.
AtomToast commentedon Mar 2, 2018
Sadly I don't think thats possible at least as far as I know :/
Naramsim commentedon Mar 2, 2018
Try this: https://calebmadrigal.com/calling-sync-code-from-asyncio/
AtomToast commentedon Mar 2, 2018
Hm, that actually sounds promissing for now. I will give it a go!
Still, a fully asynchronous wrapper might be neat at some point .-. Since this does look kinda wonky and always adds an extra step. But as long as it works 😅 💪
Naramsim commentedon Mar 2, 2018
Yep, feel free to fork Greg repo and make an async one 😄
Can I close?
AtomToast commentedon Mar 2, 2018
I had a look at it but that would be a bigger thing from what I saw as it was a bit more extensive. Might consider it again eventually though.
Yeah feel free to close. I think your solution is good enough for me. Thanks alot!
GregHilmes commentedon Mar 2, 2018
Sorry for neglecting the conversation for so long. I'm interested in an async wrapper, I just don't have the experience or the time to do that at the moment. That being said, I like the simplicity of having non-async calls, especially for new programmers using this to learn, along with PokeAPI. Perhaps
pokebase-asynccould be another fork/repo which is a separate PyPI package, give the time to put that together. @AtomToast, I would do as @Naramsim suggested, and fork my repo and build the async wrapper, and of course, in the meantime, use this with your bot. Closing now.Tmpod commentedon Jan 18, 2019
Howdy there!
Sry for posting on this closed issue but I've been looking for an async fork of this and I haven't found anything. So, since I'm quite experienced with the async framework and I've already done another async API wrapper (for Hypixel), I'd like to do that. I will start working on it as soon as I can and I'll post a message in this thread once it's done/usable.
Is that OK?
Naramsim commentedon Jan 18, 2019
For sure you can!