I have an application where I use requests to download .mp3 files from a server.
The code looks like this:
self.client = requests.session(headers={'User-Agent': self.useragent})
def download(self, url, name):
request = self.client.get(url)
with open(name, "wb") as code:
code.write(request.content)
print "done"
The problem is that when the download is finished, python does not clear the memory, so everytime I download an mp3, the memory usage of the application raises by the size of the mp3. The memory does not get cleared again, leading to my app using a lot of memory.
I assume this has to do with how I save the file, or how requests.session works.
Any suggestions.
Edit:
Here is the code:
https://github.com/Simon1988/VK-Downloader
The relevant part is in lib/vklib.py
You could try streaming the content in chunks: