Skip to content

Instantly share code, notes, and snippets.

@slingamn
Created September 14, 2012 04:07
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/955bfeaded8099b1a99f to your computer and use it in GitHub Desktop.
Save slingamn/955bfeaded8099b1a99f to your computer and use it in GitHub Desktop.
import httplib
class Instrumented(httplib.HTTPResponse):
def close(self):
print "close intercepted!!!!!"
import traceback
traceback.print_stack()
if self.fp:
self.fp.close()
self.fp = None
httplib.HTTPResponse = Instrumented
httplib.HTTPConnection.response_class = Instrumented
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')
r = reqsess.get(r'http://www.google.in/')
d = r.text
finally:
reqsess.close()
print "_fp is", r.history[0].raw._fp
print "_fp.fp is", r.history[0].raw._fp.fp
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