Coder Social home page Coder Social logo

Issue with session closing about spotify.py HOT 3 CLOSED

mental32 avatar mental32 commented on May 30, 2024
Issue with session closing

from spotify.py.

Comments (3)

mental32 avatar mental32 commented on May 30, 2024 1

Although... with hindsight. The rationale behind the lack of an async context manager for User objects seems a little nonsensical, the following situation could be possible:

async with User.from_token(client, token) as user:
    ...
# Or alternatively
async with client.user_from_token(token) as user:
    ...

I think I'll add this and roll a new release by the end of today to address this lopsided design.

from spotify.py.

mental32 avatar mental32 commented on May 30, 2024

Every spotify.Client and http enabledspotify.User objects have an aiohttp.ClientSession open underneath them.

aiohttp will emit errors/warnings for when the sessions are inappropriately destroyed, the solution is to properly close the sessions. spotify.Client has a close method which will close the underlying client session, spotify.User objects have a http attribute that have a close method for their respective session. You must call these methods when you are discarding the objects.

The library provides an asynchronous context manager for spotify.Client so you don't have to worry about the Client at least:

async with Client(...) as client:
    await stuff

There is currently no such implementation for User objects, since they're intended to be created by other models, the client itself or via one of the User constructors such as from_code or from_token. The solution there is to call user.http.close() yourself.

I'm unable to recall the extent that spotify.sync supports the close calls, so if there are issues there let me know :)

from spotify.py.

mental32 avatar mental32 commented on May 30, 2024

PS: the close methods are coroutine functions, they must be awaited.

from spotify.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.