-
-
Save eranrund/3683421 to your computer and use it in GitHub Desktop.
This file contains 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 traceback | |
import os | |
orig_close = os.close | |
def patched_close(*args, **kwargs): | |
print '----------------------------' | |
print 'os.close!',args,kwargs | |
traceback.print_stack() | |
return orig_close(*args, **kwargs) | |
os.close = patched_close | |
import socket,traceback | |
orig_socket = socket.socket | |
class wrap_socket(orig_socket): | |
def __init__(self, *args, **kwargs): | |
orig_socket.__init__(self, *args, **kwargs) | |
#print '------------------------------' | |
#traceback.print_stack() | |
print '--> new sock', self.fileno() | |
def close(self): | |
print '--> before close sock', self.fileno() | |
#traceback.print_stack() | |
orig_socket.close(self) | |
print '--> after close sock' | |
socket.socket = wrap_socket | |
import requests | |
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() | |
import os | |
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