Created
May 10, 2016 01:22
-
-
Save wention/352beb956eb588d4cf76516c80c71ae7 to your computer and use it in GitHub Desktop.
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 __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