Closed boo-dev closed 6 years ago
Why would you close the session after a player request, and if we wanted more than one requests?
Completely overlooked that part, kind of new to async functions and was just trying to remedy the error. Will look more into it before submitting another request
Should work now, just call await client.close()
when you are ready to close the session.
Example:
async def main():
client = pynite.Client(token, timeout=5)
platform = 'pc'
usernames = ['drlupo', 'tsm_myth']
for usr in usernames:
player = await client.get_player(platform, usr)
solos = await player.get_solos()
print(player.account_id) # prints account id
print(solos.kills.value) # prints the number of kills you have in solos
await client.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Is client.close() a coroutine that your awaiting it? It didn't mention it in docs
Reading through the asyncio docs it seems like we should be able to just close the loop once it's done running with loop.close() https://docs.python.org/3/library/asyncio-task.html#example-chain-coroutines
I just added my own function in the Client class that closes the session when called but it may not be the ideal way to do things. Wondering why loop.close() doesn't work in this case?
@Elemxnt just add what you sent in that comment to example.py in the examples folder and i'll merge the pr :)
@SharpBit found what i believe to be a better way to do it from here https://github.com/aio-libs/aiohttp/issues/2800 should be the most ideal way to do this as you do not need to call any new functions in your own code, as once your loop is done running it knows to close the session
Ok, nice.
Woops, closed instead of merge by accident
Fixes the problem with issue #5 in which it errors saying the client session is unclosed