title: Python dict.get() Lock
body: <p>When I use <code>dictionary.get()</code> function, is it locking the whole dictionary? I am developing a multiprocess and multithreading program. The dictionary is used to act as a state table to keep track of data. I have to impose a size limit to the dictionary, so whenever the limit is being hit, I have to do garbage collection on the table, based on the timestamp. The current implementation will delay adding operation while garbage collection is iterating through the whole table.</p>
  
  <p>I will have 2 or more threads, one just to add data and one just to do garbage collection. Performance is <em>critical</em> in my program to handle streaming data. My program is receiving streaming data, and whenever it receives a message, it has to look for it in the state table, then add the record if it's non-existent in the first place, or copy certain information and then send it along the pipe.</p>
  
  <p>I have thought of using <code>multiprocessing</code> to do the search and adding operation concurrently, but if I used processes, I have to make a copy of state table for each process, in that case, the performance overhead for synchronization is too high. And I also read that <code>multiprocessing.manager.dict()</code> is also locking the access for each CRUD operation. I could not spare the overhead for it so my current approach is using threading.</p>
  
  <p>So my question is while one thread is doing <code>.get()</code>, <code>del dict['key']</code> operation on the table, will the other insertion thread be blocked from accessing it? </p>
  
  <p>Note: I have read through most <em>SO</em>'s python dictionary related posts, but I cannot seem to find the answer. Most people only answer that even though python dictionary operations are atomic, it is safer to use a <strong>Lock</strong> for insertion/update. I'm handling a huge amount of streaming data so <strong>Locking</strong> every time is not ideal for me. Please advise if there is a better approach.</p>