title: Is there a way to perform test-and-set operation on dict in python?
body: <p>I have a multithreaded app in which I need to use a global dict to remember and handle requests.</p>
  
  <p>The problem is, I am not supposed to perform the same request twice, so I need dict to be able to test if the key exists. if not, insert it, if it does, report error.</p>
  
  <p>All code runs in python so GIL should not be relevant.</p>
  
  <p>Is that feasible in python?</p>
  
  <p>Here lock would work but I am trying to find a more natural way to solve it.</p>