def testLock(self): with lockfile.lock(self.cache_dir): # cached dir locked, attempt to lock it again with self.assertRaises(lockfile.LockError): with lockfile.lock(self.cache_dir): pass with lockfile.lock(self.cache_dir): pass
def populate(self, depth=None, no_fetch_tags=False, shallow=False, bootstrap=False, verbose=False, lock_timeout=0, reset_fetch_config=False): assert self.GetCachePath() if shallow and not depth: depth = 10000 gclient_utils.safe_makedirs(self.GetCachePath()) with lockfile.lock(self.mirror_path, lock_timeout): try: self._ensure_bootstrapped(depth, bootstrap, reset_fetch_config) self._fetch(self.mirror_path, verbose, depth, no_fetch_tags, reset_fetch_config) except ClobberNeeded: # This is a major failure, we need to clean and force a bootstrap. gclient_utils.rmtree(self.mirror_path) self.print(GIT_CACHE_CORRUPT_MESSAGE) self._ensure_bootstrapped(depth, bootstrap, reset_fetch_config, force=True) self._fetch(self.mirror_path, verbose, depth, no_fetch_tags, reset_fetch_config)
def save(self) : """ Save file """ root = current_app.root_path flat_pages_root = current_app.config.get(u'FLATPAGES_ROOT') root_path = op.join(root, flat_pages_root) # check path path = self._construct_path() if self.path and self.path != path : # delete file self.delete() # update config if not self.published : self.published = datetime.now() if not self.meta.get(u'author') : self._setmeta(u'author', current_user.get_id()) self.path = path final_path = op.join(root_path, self.path) + u'.md' # save in file with lock(final_path) : with open(final_path, 'w') as sa : sa.write(self._meta_yaml.encode(u'utf-8')) sa.write('\n') sa.write(self.body.encode(u'utf-8'))
def content(self): """ Page content or None if file does not exists """ if not op.exists(self.path): return None # lock file to prevent concurrent access with lock(self.path): return open(self.path).read().decode('utf-8')
def f2(): '''f2 enters second in l.lock (controlled by q_f1).''' logging.debug('f2: started, consuming q_f1') q_f1.get(timeout=1) # wait for f1 to execute lock q_f1.task_done() logging.debug('f2: done waiting for q_f1, locking') with lockfile.lock(self.cache_dir, timeout=1): logging.debug('f2: locked') results.put(True)
def _load_file(self, path, filename): """ Implements of lockfile """ mtime = os.path.getmtime(filename) cached = self._file_cache.get(filename) if cached and cached[1] == mtime: page = cached[0] else: with lock(filename) : with open(filename) as fd: content = fd.read().decode(self.config('encoding')) page = self._parse(content, path) self._file_cache[filename] = page, mtime return page
def f1(): '''f1 enters first in l.lock (controlled via q_f1). It then waits for side_effect to put a message in queue q_sleep.''' logging.debug('f1 started, locking') with lockfile.lock(self.cache_dir, timeout=1): logging.debug('f1: locked') q_f1.put(True) logging.debug('f1: waiting on q_f1 to be consumed') q_f1.join() logging.debug('f1: done waiting on q_f1, getting q_sleep') q_sleep.get(timeout=1) results.put(True) logging.debug('f1: lock released') q_sleep.task_done() logging.debug('f1: exiting')
def content(self, value): """ Save or remove object :param value: New content if `None` or empty then file is removed """ # delete page if not value: if op.exists(self.path): os.remove(self.path) # save content else: # get path dirname = op.dirname(self.path) # create path if not exists if not op.exists(dirname): os.makedirs(dirname) # lock file to prevent concurrent access with lock(self.path): with open(self.path, 'wb') as page: page.write(value.encode('utf-8'))
sp.call(['scp', program, "[email protected]:/root/nfs-shared/"]) program_name=program.split('/')[-1] program_exec = program_name.split('.')[0] time.sleep(3) sp.call("ssh [email protected] 'mpicc /root/nfs-shared/"+program_name+" -o /root/nfs-shared/"+program_exec+"'",shell=True) runCount = int(options.nodes) pCount = 0 allRun = 0 someRun = 0 choice = [0] stateFile = 'pstate.txt' with lock(stateFile): fd = open(stateFile, 'r') state = fd.readline().split() pCount = len(state) if pCount == 0: print "Please check pstate.txt" sys.exit(1) state = [int(elem) for elem in state] choice = sorted(range(pCount), key=lambda k: state[k]) allRun = runCount/pCount someRun = runCount%pCount fd.close() fd = open(stateFile, 'w') if allRun > 0: for pos in range(len(state)): if state[pos] == 0 and pos <> 0: