Skip to content

Instantly share code, notes, and snippets.

@Bluehorn
Created March 29, 2012 06:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bluehorn/2234274 to your computer and use it in GitHub Desktop.
Save Bluehorn/2234274 to your computer and use it in GitHub Desktop.
Simple example that shows how the requests module does not clean up connections
import gc, os, subprocess, requests
gc.disable() # Just to make sure - I have seen this with gc enabled
for x in range(20):
requests.head("http://www.google.de/")
print "Open sockets after 20 head requests:"
pid = os.getpid()
subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)
gcresult = gc.collect()
print "Garbage collection result: %s" % (gcresult,)
print "Open sockets after garbage collection:"
subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment