Skip to content

Instantly share code, notes, and snippets.

@JustinVenus
Created August 10, 2013 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JustinVenus/6198591 to your computer and use it in GitHub Desktop.
Save JustinVenus/6198591 to your computer and use it in GitHub Desktop.
see if this helps graphite and droned.
import os
__all__ = ["open","mkdir"]
__author__ = "Justin Venus <justin.venus@gmail.com>"
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