Global distributed lock
166659
def lock(self, name, **kwargs):
        
        return self.pubsub.store.client().lock(self.prefixed(name), **kwargs)
436027
def interprocess_locked(path):
    """"""

    lock = InterProcessLock(path)

    def decorator(f):

        @six.wraps(f)
        def wrapper(*args, **kwargs):
            with lock:
                return f(*args, **kwargs)

        return wrapper

    return decorator
624144
def sync(lock):
    
    def sync(f):
        @wraps(f)
        def new_function(*args, **kwargs):
            lock.acquire()
            try:
                return f(*args, **kwargs)
            finally:
                lock.release()
        return new_function
    return sync
565930
public function lock() {
        $this->primaryPrivateKey = null;
        $this->secret = null;
        $this->primarySeed = null;
        $this->locked = true;
    }
692576
def synchronized(func, *args, **kwargs):
    
    if not (args and hasattr(args[0], '_lock')):
        return func(*args, **kwargs)
    with args[0]._lock: # pylint: disable=W0212
        return func(*args, **kwargs)
1356681
function takeGlobalQueue() {
            //Push all the globalDefQueue items into the context's defQueue
            if (globalDefQueue.length) {
                //Array splice in the values since the context code has a
                //local var ref to defQueue, so cannot just reassign the one
                //on context.
                apsp.apply(defQueue,
                           [defQueue.length - 1, 0].concat(globalDefQueue));
                globalDefQueue = [];
            }
        }
648651
def atlas_peer_table_lock():
    
    global PEER_TABLE_LOCK, PEER_TABLE, PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK

    if PEER_TABLE_LOCK_HOLDER is not None:
        assert PEER_TABLE_LOCK_HOLDER != threading.current_thread(), "DEADLOCK"
        # log.warning("\n\nPossible contention: lock from %s (but held by %s at)\n%s\n\n" % (threading.current_thread(), PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK))

    PEER_TABLE_LOCK.acquire()
    PEER_TABLE_LOCK_HOLDER = threading.current_thread()
    PEER_TABLE_LOCK_TRACEBACK = traceback.format_stack()

    # log.debug("\n\npeer table lock held by %s at \n%s\n\n" % (PEER_TABLE_LOCK_HOLDER, PEER_TABLE_LOCK_TRACEBACK))
    return PEER_TABLE
235494
private void registerGlobalTxTable(GlobalComponentRegistry globalComponentRegistry) {
      InternalCacheRegistry registry = globalComponentRegistry.getComponent(InternalCacheRegistry.class);
      ConfigurationBuilder builder = new ConfigurationBuilder();
      //we can't lose transactions. distributed cache can lose data is num_owner nodes crash at the same time
      builder.clustering().cacheMode(globalComponentRegistry.getGlobalConfiguration().isClustered() ?
            CacheMode.REPL_SYNC :
            CacheMode.LOCAL);
      builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL);
      //persistent? should we keep the transaction after restart?
      registry.registerInternalCache(GLOBAL_TX_TABLE_CACHE_NAME, builder.build(),
            EnumSet.noneOf(InternalCacheRegistry.Flag.class));
   }
245010
public synchronized boolean lock() throws KeeperException, InterruptedException {
        if (isClosed()) {
            return false;
        }
        ensurePathExists(dir);

        return (Boolean) retryOperation(zop);
    }
242084
def lock_access(repository_path, callback):
    

    with open(cpjoin(repository_path, 'lock_file'), 'w') as fd:
        try:
            fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            returned = callback()
            fcntl.flock(fd, fcntl.LOCK_UN)
            return returned
        except IOError:
            return fail(lock_fail_msg)
883923
def _lock(self, timeout_ms=-1):
        """"""
        vbox = VirtualBox()
        machine = vbox.find_machine(self.machine_name)
        wait_time = 0
        while True:
            session = Session()
            try:
                machine.lock_machine(session, LockType.write)
            except Exception as exc:
                if timeout_ms != -1 and wait_time > timeout_ms:
                    raise ValueError("Failed to acquire lock - %s" % exc)
                time.sleep(1)
                wait_time += 1000
            else:
                try:
                    yield session
                finally:
                    session.unlock_machine()
                break
684533
function distributed_task(taskDef) {
	var worker = this[0], taskId = this[1], taskDef2;

	function replace_task_self(obj) {
		if (typeof(obj) == 'object') {
			for (var key in obj) {
				var value = obj[key];
				if (isDistributedTask(value) && (value.map === worker.TASK_SELF)) {
					value.map = taskId
				}
				else if (value instanceof Array) {
					value.forEach(replace_task_self)
				}
				else replace_task_self(value)
			}
		}
	}

	try {
		taskDef2 = def.decode(taskDef)
	}
	catch (e) {
		return worker.default_rejected({action: 'taskDef:decode', reason: e, task: taskId})
			.then(reject_me.bind("decode exception '" + e.message + "'for downloaded " + taskId));
	}

	// define taskDef.taskId
	Object.defineProperty(taskDef2, "taskId",
		{ "value": taskId, "enumerable": false, "writable": false, "configurable": false });

	// replace TASK_SELF in task.map only, with task.run.arguments.map
	replace_task_self(taskDef2);

	// call taskDef.distributed
	if ('distributed' in taskDef2) {
		try {
			taskDef2.distributed.call(worker, taskDef2)
		}
		catch (e) {
			return worker.default_rejected({action: 'taskDef:distributed', reason: e, task: taskId})
				.then(reject_me.bind("distributed method exception '" + e.message + "'in " + taskId));
		}
	}

	return taskDef2
}
906290
def sync():
    '''
    
    '''
    # Funtoo patches eix to use 'ego sync'
    if __grains__['os'] == 'Funtoo':
        cmd = 'eix-sync -q'
    else:
        cmd = 'eix-sync -q -C "--ask" -C "n"'
    if 'makeconf.features_contains' in __salt__ and __salt__['makeconf.features_contains']('webrsync-gpg'):
        # GPG sign verify is supported only for "webrsync"
        if salt.utils.path.which('emerge-delta-webrsync'):  # We prefer 'delta-webrsync' to 'webrsync'
            cmd += ' -W'
        else:
            cmd += ' -w'
        return __salt__['cmd.retcode'](cmd) == 0
    else:
        if __salt__['cmd.retcode'](cmd) == 0:
            return True
        # We fall back to "webrsync" if "rsync" fails for some reason
        if salt.utils.path.which('emerge-delta-webrsync'):  # We prefer 'delta-webrsync' to 'webrsync'
            cmd += ' -W'
        else:
            cmd += ' -w'
        return __salt__['cmd.retcode'](cmd) == 0
878800
def lock(instance_id, profile=None, **kwargs):
    '''
    

    '''
    conn = _auth(profile, **kwargs)
    return conn.lock(instance_id)
802019
def lock(self):
        """"""
        
        self.password = None
        self.keyfile = None
        self.groups[:] = []
        self.entries[:] = []
        self._group_order[:] = []
        self._entry_order[:] = []
        self.root_group = v1Group()
        self._num_groups = 1
        self._num_entries = 0
        return True
1283975
def whisper_lock_writes(self, cluster='main'):
        """"""
        if not self.config.has_section(cluster):
            raise SystemExit("Cluster '%s' not defined in %s"
                             % (cluster, self.config_file))
        try:
            return bool(self.config.get(cluster, 'whisper_lock_writes'))
        except NoOptionError:
            return False
232144
private void primAdd(IEntityLock lock, Date expiration) throws LockingException {
        long now = System.currentTimeMillis();
        long willExpire = expiration.getTime();
        long cacheIntervalSecs = (willExpire - now) / 1000;

        if (cacheIntervalSecs > 0) {
            SmartCache sc = (SmartCache) getLockCache(lock.getEntityType());

            synchronized (sc) {
                sc.put(getCacheKey(lock), lock, (cacheIntervalSecs));
            }
        }
        // Else the lock has already expired.
    }