How to use the filelock.filelock function in filelock

To help you get started, we’ve selected a few filelock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github su2code / SU2 / SU2_PY / SU2 / io / data.py View on Github external
try:
        import scipy.io
        scipy_loaded = True
    except ImportError:
        scipy_loaded = False
        
    # process file format
    if file_format == 'infer':
        if   os.path.splitext(file_name)[1] == '.mat':
            file_format = 'matlab'
        elif os.path.splitext(file_name)[1] == '.pkl':
            file_format = 'pickle'
    assert file_format in ['matlab','pickle'] , 'unsupported file format'

    # get filelock
    with filelock(file_name):
        
        # if appending needed 
        # TODO: don't overwrite other core_names
        if append == True and os.path.exists(file_name):
            # check file exists
            if not os.path.exists(file_name):
                raise Exception , 'Cannot append, file does not exist: %s' % file_name  
            # load old data
            data_dict_old = load( file_name   = file_name   ,
                                  var_names   = None        ,
                                  file_format = file_format ,
                                  core_name   = core_name    )
            # check for keys not in new data
            for key,value in data_dict_old.iteritems():
                if not data_dict.has_key(key):
                    data_dict[key] = value
github suavecode / SUAVE / trunk / SUAVE / Core / Input_Output.py View on Github external
except ImportError:
        scipy_loaded = False    
        
    if not os.path.exists(file_name):
        raise Exception , 'File does not exist: %s' % file_name
    
    # process file format
    if file_format == 'infer':
        if   os.path.splitext(file_name)[1] == '.mat':
            file_format = 'matlab'
        elif os.path.splitext(file_name)[1] == '.pkl':
            file_format = 'pickle'
    assert file_format in ['matlab','pickle'] , 'unsupported file format'
        
    # get filelock
    with filelock(file_name):    
    
        # LOAD MATLAB
        if file_format == 'matlab' and scipy_loaded:
            input_data = scipy.io.loadmat( file_name        = file_name ,
                                           squeeze_me       = False     ,
                                           chars_as_strings = True      ,
                                           struct_as_record = True       )
            # pull core variable
            assert input_data.has_key(core_name) , 'core data field "%s%" not found' % core_name
            input_data = input_data[core_name]
            
            # convert recarray to dictionary
            input_data = rec2dict(input_data)
            
        # LOAD PICKLE
        elif file_format == 'pickle':
github su2code / SU2 / SU2_PY / SU2 / io / data.py View on Github external
except ImportError:
        scipy_loaded = False    
        
    if not os.path.exists(file_name):
        raise Exception , 'File does not exist: %s' % file_name
    
    # process file format
    if file_format == 'infer':
        if   os.path.splitext(file_name)[1] == '.mat':
            file_format = 'matlab'
        elif os.path.splitext(file_name)[1] == '.pkl':
            file_format = 'pickle'
    assert file_format in ['matlab','pickle'] , 'unsupported file format'
        
    # get filelock
    with filelock(file_name):    
    
        # LOAD MATLAB
        if file_format == 'matlab' and scipy_loaded:
            input_data = scipy.io.loadmat( file_name        = file_name ,
                                           squeeze_me       = False     ,
                                           chars_as_strings = True      ,
                                           struct_as_record = True       )
            # pull core variable
            assert input_data.has_key(core_name) , 'core data not found'
            input_data = input_data[core_name]
            
            # convert recarray to dictionary
            input_data = rec2dict(input_data)
            
        # LOAD PICKLE
        elif file_format == 'pickle':
github suavecode / SUAVE / trunk / SUAVE / Core / Input_Output.py View on Github external
try:
        import scipy.io
        scipy_loaded = True
    except ImportError:
        scipy_loaded = False
        
    # process file format
    if file_format == 'infer':
        if   os.path.splitext(file_name)[1] == '.mat':
            file_format = 'matlab'
        elif os.path.splitext(file_name)[1] == '.pkl':
            file_format = 'pickle'
    assert file_format in ['matlab','pickle'] , 'unsupported file format'

    # get filelock
    with filelock(file_name):
        
        # if appending needed 
        # TODO: don't overwrite other core_names
        if append == True and os.path.exists(file_name):
            # check file exists
            if not os.path.exists(file_name):
                raise Exception , 'Cannot append, file does not exist: %s' % file_name  
            # load old data
            data_dict_old = load_data( file_name   = file_name   ,
                                       file_format = file_format ,
                                       core_name   = core_name    )
            # check for keys not in new data
            for key,value in data_dict_old.iteritems():
                if not data_dict.has_key(key):
                    data_dict[key] = value
            #: for each dict item

filelock

A platform independent file lock.

Unlicense
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis