beetbox / pyacoustid

Python bindings for Chromaprint acoustic fingerprinting and the Acoustid Web service
MIT License
325 stars 66 forks source link

Close "Session" socket when finished #52

Closed Javinator9889 closed 5 years ago

Javinator9889 commented 5 years ago

By using just:

session = requests.Session()
# stuff
try:
    return response.json()
except ValueError:
    raise WebServiceError("···")

the Session is not closed so there is a STREAM (SocketKind.SOCK_STREAM) opened until the Python application finishes.

By using the with statement, we ensure that even if an unhandled exception is thrown the socket will be always closed (see: Advanced Usage - Session Objects)

sampsyo commented 5 years ago

Excellent; thank you!!