def acquire_lock(self, app_id, txid, entity_key):
    logging.debug("Acquiring lock for appid {0}, transaction id {1}, " \
      "entity key {2}".format(app_id, txid, entity_key))

    if self.needs_connection or not self.handle.connected:
      self.reestablish_connection()

    lockrootpath = self.get_lock_root_path(app_id, entity_key)

    try:
      if self.is_in_transaction(app_id, txid):  # use current lock
        transaction_lock_path = self.get_transaction_lock_list_path(
          app_id, txid)
        prelockpath = self.run_with_retry(self.handle.get,
          transaction_lock_path)[0]
        lock_list = prelockpath.split(LOCK_LIST_SEPARATOR)
        logging.debug("Lock list: {0}".format(lock_list))
        if lockrootpath in lock_list:
          logging.debug("Already has lock: {0}".format(lockrootpath))
          return True
        else:
          if self.is_xg(app_id, txid):
            return self.acquire_additional_lock(app_id, txid, entity_key,
              create=False)
          else:
            raise ZKBadRequest("acquire_lock: You can not lock " \
              "different root entity in non-cross-group transaction.")
    except ZKInternalException as zk_exception:
      logging.exception(zk_exception)
      self.reestablish_connection()
      raise ZKTransactionException("An internal exception prevented us from " \
        "getting the lock for app id {0}, txid {1}, entity key {2}" \
        .format(app_id, txid, entity_key))
    except kazoo.exceptions.KazooException as kazoo_exception:
      logging.exception(kazoo_exception)
      self.reestablish_connection()
      raise ZKTransactionException("Couldn't get lock for app id {0}, txid " \
        "{1}, entity key {2}".format(app_id, txid, entity_key))

    return self.acquire_additional_lock(app_id, txid, entity_key, create=True)
Acquire lock for transaction. It will acquire additional locks
dataset/ETHPy150Open AppScale/appscale/AppDB/zkappscale/zktransaction.py/ZKTransaction.acquire_lock