Skip to content

Instantly share code, notes, and snippets.

@slingamn
Forked from eranrund/gist:3313868
Created August 10, 2012 21:38
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/3318253 to your computer and use it in GitHub Desktop.
Save slingamn/3318253 to your computer and use it in GitHub Desktop.
demonstrates python-requests socket leak
import requests
import os
import subprocess
pid = os.getpid()
reqsess = requests.session()
try:
r = reqsess.get(r'http://www.mouser.com/Search/Refine.aspx?Keyword=test')
d = r.text
finally:
reqsess.close()
print 'done, calling lsof'
subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment