Created
March 29, 2012 06:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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