Skip to content

Instantly share code, notes, and snippets.

@slingamn
Created December 18, 2012 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slingamn/4332611 to your computer and use it in GitHub Desktop.
Save slingamn/4332611 to your computer and use it in GitHub Desktop.
old leak test from kennethreitz/requests#520
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.com/")
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