I need to pass data between two Python scripts that are initiated from two different sources. I have seen my logger with a read errors. Is there a better way?

**Program A:** Regularly writes to a pickle file about every minute.

```
def cacheData(filepath, data):
    #create a cPickle file to cache the current data
    try:  
        outFile = open(filepath,'wb')  
        #cPickle the current data to a file  
        cPickle.dump(data, outFile)  
        outFile.close()   
    except Exception, e:  
        logger.warn("Error creating cache file")  

```

**Program B:** Is a compiled executable initiated by the user. It reads the pickle file to initiate some code. 

```
def readCachedObj(filepath):
    #read cPickle file and return data as object
    try:
        inFile = open(filepath,'rb')
        cache = cPickle.load(inFile)
        inFile.close()
        return cache
    except Exception, e:
        logger.warn("Error reading cached data cPickle")

```

UPDATE 1
========

```
def replace(src, dst):
    win32api.MoveFileEx(src, dst, win32con.MOVEFILE_REPLACE_EXISTING)    

def cacheData(filepath, data):
    #create a cPickle file to cache the current data
    try:  
        tmpfile = str(uuid.uuid4()) + '.tmp'
        outFile = open(tmpfile,'wb')  
        #cPickle the current data to a temp file  
        cPickle.dump(data, outFile)  
        outFile.close()  
        #replace the pickle file with the new temp file
        replace(tmpfile, filepath)    
        #remove any extraneous temp files
        for f in glob.glob("*.tmp"):
            os.remove(f)        
    except Exception, e:  
        logger.warn("Error creating cache file")  

def readCachedObj(filepath):
    #read cPickle file and return data as object
    try:     
        inFile = open(filepath,'rb')
        cache = cPickle.load(inFile)
        inFile.close()
        return cache
    except Exception, e:
        logger.warn("Error reading cached data cPickle")      

```