Skip to content

Instantly share code, notes, and snippets.

@wention
Created May 10, 2016 01:22
Show Gist options
  • Select an option

  • Save wention/352beb956eb588d4cf76516c80c71ae7 to your computer and use it in GitHub Desktop.

Select an option

Save wention/352beb956eb588d4cf76516c80c71ae7 to your computer and use it in GitHub Desktop.
import __builtin__
openfiles = set()
oldfile = __builtin__.file
class newfile(oldfile):
def __init__(self, *args):
self.x = args[0]
print "\033[01;31m##### %d #### OPENING %s ###\033[00m" % (len(openfiles),str(self.x))
oldfile.__init__(self, *args)
openfiles.add(self)
def close(self):
print "\033[01;31m##### %d #### CLOSING %s ###\033[00m" % (len(openfiles),str(self.x))
oldfile.close(self)
openfiles.remove(self)
oldopen = __builtin__.open
def newopen(*args):
return newfile(*args)
__builtin__.file = newfile
__builtin__.open = newopen
def printOpenFiles():
print "\033[01;31m############### %d OPEN FILES: ###############\033[00m" % len(openfiles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment