def cache(self,name,suffix=''):
"""Allocate a name in cache, if cache was setup
also lock the file , so that another process have to wait before using the same file name
Important: call unlock() on result
"""
#TODO: something more clever here?
fname=''
if self.work_dir is not None:
fname=self.cache_dir+os.sep+name+suffix
lock_name=fname+'.lock'
f=self._locks[lock_name]=open(lock_name, 'a')
fcntl.lockf(f.fileno(), fcntl.LOCK_EX )
else:
fname=self.tmp(name+suffix)
return fname
评论列表
文章目录