How do I delete an instance of a class in python (by force)?

Shane picture Shane · Dec 30, 2010 · Viewed 9.5k times · Source

I'm using a script to test if a website runs smoothly, basically I open the site every 20 minutes or so and check the response time and so on. Like this:

while True:

    MechBrowser = mechanize.Browser()
    Response = MechBrowser.open("http://example.com")
    time.sleep(1000)

I know python will do garbage collection itself and we should really not bother, but when I check network monitor I always find several unclosed connection each running 1h or more. And not all of the connection opened would hang there, just some of them. I'm confused, or maybe there's a method to destroy these instances manually?

Answer

Keith picture Keith · Dec 30, 2010

Try also closing your response object.