The search_album and search_artist methods could definitely benefit from threading. I added the num_workers parameter for the user to define the number of threads used. If the user just used the default num_workers=1, no threading is used and the songs are downloaded like they were before.
As for thread safety:
Python lists are inherently thread-safe and we just add the created songs to the list. So I don't see any issues with artist.songs.
The artist.num_songs attribute isn't thread-safe and we'd need to set setter/getters and a threading.lock if we wanted to keep that attribute. Instead, I removed it and substituted it with len(artist.songs).
The requests.Session object is not thread-safe and it's recommended to use one Session per thread. But considering that we don't modify the Session at all in this solution, I don't think that'll be a problem. Although it needs a little more investigation.
The
search_album
andsearch_artist
methods could definitely benefit from threading. I added thenum_workers
parameter for the user to define the number of threads used. If the user just used the defaultnum_workers=1
, no threading is used and the songs are downloaded like they were before. As for thread safety:artist.songs
.artist.num_songs
attribute isn't thread-safe and we'd need to set setter/getters and athreading.lock
if we wanted to keep that attribute. Instead, I removed it and substituted it withlen(artist.songs)
.requests.Session
object is not thread-safe and it's recommended to use one Session per thread. But considering that we don't modify the Session at all in this solution, I don't think that'll be a problem. Although it needs a little more investigation.Checklist