def addOrThrow(self, hdfpath, hdfstorage): if hdfpath in self.__paths: raise omero.LockTimeout( None, None, "Path already in HdfList: %s" % hdfpath) parent = path(hdfpath).parent if not parent.exists(): raise omero.ApiUsageException( None, None, "Parent directory does not exist: %s" % parent) hdffile = hdfstorage.openfile("a") fileno = hdffile.fileno() try: portalocker.lockno( fileno, portalocker.LOCK_NB | portalocker.LOCK_EX) except portalocker.LockException: hdffile.close() raise omero.LockTimeout( None, None, "Cannot acquire exclusive lock on: %s" % hdfpath, 0) except: hdffile.close() raise if fileno in self.__filenos.keys(): hdffile.close() raise omero.LockTimeout( None, None, "File already opened by process: %s" % hdfpath, 0) else: self.__filenos[fileno] = hdfstorage self.__paths[hdfpath] = hdfstorage return hdffile
def loop(self, loops, ms): """ Calls block(long) "loops" number of times with the "ms" argument. This means the total wait time for the delete to occur is: loops X ms. Sensible values might be 10 loops for 500 ms, or 5 seconds. @param loops Number of times to call block(long) @param ms Number of milliseconds to pass to block(long @throws omero.LockTimeout if block(long) does not return a non-null value after loops calls. """ count = 0 found = False while count < loops: count += 1 found = self.block(ms) if found: break if found: return self.getResponse() else: waited = (old_div(ms, 1000.0)) * loops raise omero.LockTimeout( None, None, "Command unfinished after %s seconds" % waited, 5000, int(waited))
def addOrThrow(self, hdfpath, hdfstorage): if hdfpath in self.__locks: raise omero.LockTimeout(None, None, "Path already in HdfList: %s" % hdfpath) parent = path(hdfpath).parent if not parent.exists(): raise omero.ApiUsageException(None, None, "Parent directory does not exist: %s" % parent) lock = None try: lock = open(hdfpath, "a+") portalocker.lock(lock, portalocker.LOCK_NB|portalocker.LOCK_EX) self.__locks[hdfpath] = lock except portalocker.LockException, le: if lock: lock.close() raise omero.LockTimeout(None, None, "Cannot acquire exclusive lock on: %s" % hdfpath, 0)
except portalocker.LockException, le: if lock: lock.close() raise omero.LockTimeout( None, None, "Cannot acquire exclusive lock on: %s" % hdfpath, 0) except: if lock: lock.close() raise hdffile = hdfstorage.openfile("a") fileno = hdffile.fileno() if fileno in self.__filenos.keys(): hdffile.close() raise omero.LockTimeout( None, None, "File already opened by process: %s" % hdfpath, 0) else: self.__filenos[fileno] = hdfstorage self.__paths[hdfpath] = hdfstorage return hdffile @locked def getOrCreate(self, hdfpath): try: return self.__paths[hdfpath] except KeyError: return HdfStorage(hdfpath, self._lock) # Adds itself. @locked def remove(self, hdfpath, hdffile):