Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:24:33+00:00 2026-06-17T05:24:33+00:00

I have an application where I use requests to download .mp3 files from a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:24:35+00:00Added an answer on June 17, 2026 at 5:24 am

    You could try streaming the content in chunks:

    def download(self, url, name):
        request = self.client.get(url, stream=True)  # `prefetch=False` for older
                                                     # versions of requests
        with open(name, "wb") as code:
            for chunk in request.iter_content(1024):
                if not chunk:
                    break
    
                code.write(chunk)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently use the code below to download files from a network server to
I have written a code to download pdf file from server, but the code
I have an ASP.NET Web Forms application. I would like to create a download
I download the appengine-rest-server (1.0.6) and try to use this module in my aplication
I have application that received data via HTTP POST requests. I'm trying to use
i have application who use specific process during running and i want to sample
Currently we have an application who use spring who support mysql. Some people prefer
I have application which needs to use a dll (also written by me) which
I have an Access application which use SQLServer 2008 R2 as database. When I
I have configured my application to use the Service configuration Local in the development

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.