title: Is there a way to execute a blocking get() call in Google Cloud Datastore?
body: <p>I have an operation that requires the following:</p>
  
  <ol>
  <li>Get entity from key, using Google Cloud Datastore</li>
  <li>Do resource (CPU/memory) intensive work for ~10 seconds</li>
  <li>Update entity with results in Google Cloud Datastore</li>
  </ol>
  
  <p>Ideally, to minimize resource use, I wouldn't want the program to even start executing #2 if there is another worker out there already in the middle of processing #2. </p>
  
  <p>That would mean the <code>get()</code> call would block until no one else is processing #2. </p>
  
  <p>My understanding from the <a href="https://cloud.google.com/datastore/docs/concepts/transactions" rel="nofollow noreferrer">docs</a> and experimenting with datastore's <code>Transaction</code>, is that any checks for contention do not occur until the <code>commit()</code> call. Only then is an error thrown and rollbacks occur. But that would mean every worker executes that expensive step #2 before realizing that someone else out there is already doing the work. </p>
  
  <p><strong>Is there a way to get the <code>get()</code> call to block if anyone else has a Transaction using that key?</strong></p>
  
  <p>In <a href="https://engineering.khanacademy.org/posts/user-write-lock.htm" rel="nofollow noreferrer">this article</a>, they utilize memcache. However, I'd prefer to keep it native to Cloud Datastore if possible, to minimize additional infrastructure.</p>