Created
August 10, 2013 01:23
-
-
Save JustinVenus/6198591 to your computer and use it in GitHub Desktop.
see if this helps graphite and droned.
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 os | |
__all__ = ["open","mkdir"] | |
__author__ = "Justin Venus <[email protected]>" | |
START_UMASK = os.umask(0) | |
os.umask(START_UMASK) | |
def mkdir(func): | |
def decorator(*args): | |
if len(args) == 1: | |
args += (int(oct(int("0777",8) - START_UMASK)),) | |
return func(*args) | |
return decorator | |
mkdir = mkdir(os.mkdir) | |
mkdir.__doc__ = os.mkdir.__doc__ | |
class ThreadSafeFile(type): | |
def __init__(classObj, name, bases, members): | |
super(ThreadSafeFile, classObj).__init__(name, bases, members) | |
classObj._umask = START_UMASK #get the original umask | |
def __call__(classObj, *args, **kwargs): | |
#allocate memory for the instance | |
instance = classObj.__new__(classObj, *args, **kwargs) | |
os.umask(classObj._umask) | |
#call constructor | |
instance.__init__(*args, **kwargs) | |
return instance | |
class open(ThreadSafeFile('ThreadSafeFile', (file,), {})): pass | |
del START_UMASK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment